Lab BGP AS-Path access-list

利用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

下面通过两个例子来了解route-map的用法。

Step 1、配置各台路由器的IP地址,并且使用Ping命令确认各路由器的直连口的互通性。

Step 2、在R1,R2和R2,R3之间运行EBGP,并宣告环回口。
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、在R3的in方向配置route-map过滤AS2的路由。
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