Restricting Networks Advertised to a BGP Peer
Problem
You want to restrict which routes your router advertises to another AS.
Solution
There are three ways to filter routes in BGP. The first one uses extended access lists and route maps, as follows:
Router1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#access-list
105
deny ip host
172.25.0.0
host
Router1(config)#
255.255.0.0
access-list
105
permit ip any any
Router1(config)#route-map
ACL-RT-FILTER
permit
Router1(config-route-map)#
10
match ip address
Router1(config-route-map)#
105
exit
Router1(config)#route-map
ACL-RT-FILTER
deny
Router1(config-route-map)#
20
exit
Router1(config)#router bgp
Router1(config-router)#
65500
neighbor
192.168.1.5
remote-as
Router1(config-router)#
65510
neighbor
192.168.1.5
route-map
ACL-RT-FILTER
in
Router1(config-router)#exit
Router1(config)#end
Router1#
The second method uses a distribute-list:
Router1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#access-list
106
deny ip host
172.25.0.0
host
Router1(config)#
255.255.0.0
access-list
106
permit ip any any
Router1(config)#router bgp
Router1(config-router)#
65500
neighbor
192.168.1.5
remote-as
Router1(config-router)#
65510
neighbor
192.168.1.5
distribute-list
106
in
Router1(config-router)#exit
Router1(config)#end
Router1#
But the most common way to filter routes in BGP is to use prefix lists. The following example has a similar effect the preceding ones:
Router1#configure ...
Get Cisco IOS Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.