Route filtering using route-map
R1:
s0/0:12.1.1.1/24
lo0:1.1.1.1/32
R2:
s0/0:12.1.1.2/24
s0/1:23.1.1.2/24
lo0:2.2.2.2/32
R3:
s0/0:23.1.1.3/24
lo0:3.3.3.3/32
The following uses two examples to understand the usage of route-map.
Step 1. Configure the IP address of each router, and use the Ping command to confirm the interoperability of the direct connection ports of each router.
Step 2. Run EBGP between R1, R2 and R2, R3, and announce the loopback port.
R1 (config-if) #router bgp 1
R1 (config-router) #bgp router-id 1.1.1.1
R1 (config-router) #no au
R1 (config-router) #no sy
R1 (config-router) #neighbor 12.1.1.2 remote-as 2
R1 (config-router) #network 1.1.1.1 mask 255.255.255.255
R2(config)#router bgp 2
R2(config-router)#no au
R2(config-router)#no sy
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#network 2.2.2.2 mask 255.255.255.255
R2(config-router)#nei 12.1.1.1 remote-as 1
R2(config-router)#neighbor 23.1.1.3 remote-as 3
R3(config)#router bgp 3
R3(config-router)#no au
R3(config-router)#no sy
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#neighbor 23.1.1.2 remote-as 2
R3(config-router)#network 3.3.3.3 mask 255.255.255.255
Step 3. Configure route-map in the direction of R3 to filter AS2 routes.
R3 (config) #ip as-path access-list 1 deny ^ _2 $
R3 (config) #ip as-path access-list 1 permit. * // permit any
R3(config)#route-map FILTER permit 10
R3(config-route-map)#match as-path 1
R3(config)#router bgp 3
R3(config-router)#neighbor 23.1.1.2 route-map FILTER in
Step 4、查看R3的路由表,过滤成功。
R3#sh ip bgp
BGP table version is 3, local router ID is 3.3.3.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.1/32 23.1.1.2 0 2 1 i
*> 3.3.3.3/32 0.0.0.0 0 32768 i
R3#sh ip route bgp
1.0.0.0/32 is subnetted, 1 subnets
B 1.1.1.1 [20/0] via 23.1.1.2, 00:01:55