![使用前缀列表过滤BGP路由_prefix-list](https://s2.51cto.com/attachment/201002/201002051265337940156.jpg?x-oss-process=image/resize,m_fixed,w_1184)
1、配置各路由器的IP地址和BGP协议,下面来看一下详细配置:
R1(config-if)#router bgp 64512
R1(config-router)#net 172.16.0.0 mask 255.255.255.0
R1(config-router)#net 172.16.1.0 mask 255.255.255.128
R1(config-router)#net 172.16.2.0 mask 255.255.255.192
R1(config-router)#net 172.16.3.0 mask 255.255.255.224
R1(config-router)#net 172.16.4.0 mask 255.255.255.240
R1(config-router)#net 172.16.255.0 mask 255.255.255.252
R1(config-router)#nei 172.16.255.2 remote 64512
R2(config-if)#router bgp 64512
R2(config-router)#net 172.16.255.0 mask 255.255.255.252
R2(config-router)#net 10.1.255.0 mask 255.2
R2(config-router)#net 10.1.255.0 mask 255.255.255.252
R2(config-router)#nei 172.16.255.1 remote 64512
R2(config-router)#nei 10.1.255.2 remote
R2(config-router)#nei 10.1.255.2 remote 64513
R3(config-if)#router bgp 64513
R3(config-router)#net 10.1.255.0 mask 255.255.255.252
R3(config-router)#nei 10.1.255.1 remote 64512 |
R3#sh ip route
………………
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 6 subnets, 6 masks
B 172.16.255.0/30 [20/0] via 10.1.255.1, 00:00:32
B 172.16.4.0/28 [20/0] via 10.1.255.1, 00:00:02
B 172.16.0.0/24 [20/0] via 10.1.255.1, 00:00:02
B 172.16.1.0/25 [20/0] via 10.1.255.1, 00:00:02
B 172.16.2.0/26 [20/0] via 10.1.255.1, 00:00:02
B 172.16.3.0/27 [20/0] via 10.1.255.1, 00:00:02
10.0.0.0/30 is subnetted, 1 subnets
C 10.1.255.0 is directly connected, Serial1/0 |
1、R3拒绝收到172.16.0.0/24和172.16.1.0/25两条BGP路由条目,其它的BGP路由都能收到。
A:下面来看在R2上的配置:
R2(config)#ip prefix-list set_filter seq 1 deny 172.16.0.0/24
R2(config)#ip prefix-list set_filter seq 2 deny 172.16.1.0/25(建立一个名为set_filter序号为2的前缀列表拒绝172.16.1.0/25这条路由)
R2(config)#ip prefix-list set_filter seq 3 perm 0.0.0.0/0 le 32 (小于32位的子网路由会被匹配,目的是允许所有的其它路由相当于permit any的列表)
R2(config)#router bgp 64512
R2(config-router)#nei 10.1.255.2 prefix-list set_filter out(在下游出口方向对R3应用前缀列表) |
R3#sh ip route
………………
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 4 subnets, 4 masks
B 172.16.255.0/30 [20/0] via 10.1.255.1, 00:16:19
B 172.16.4.0/28 [20/0] via 10.1.255.1, 00:15:49
B 172.16.2.0/26 [20/0] via 10.1.255.1, 00:15:49
B 172.16.3.0/27 [20/0] via 10.1.255.1, 00:15:49 (有两条BGP路由不见了,其它的都能收到)
10.0.0.0/30 is subnetted, 1 subnets
C 10.1.255.0 is directly connected, Serial1/0 |
A:把之前的prefix-list NO 掉,重新配置R2:
R2(config)#no ip prefix-list set_filter seq 1 deny 172.16.0.0/24
R2(config)#no ip prefix-list set_filter seq 3 perm 0.0.0.0/0 le 32
R2(config)#no ip prefix-list set_filter seq 2 deny 172.16.1.0/25
R2(config)#router bgp 64512
R2(config-router)#no nei 10.1.255.2 prefix-list set_filter out
R2(config)#ip prefix-list set_filter seq 1 permit 172.16.3.0/27
R2(config)#ip prefix-list set_filter seq 2 permit 172.16.255.0/30
R2(config)# (和ACL一样,默认会有一条拒绝所有)
R2(config-router)#nei 10.1.255.2 prefix-list set_filter out (对R3邻居应用) |
R3#clear ip bgp * soft
R3#sh ip route
………………
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
B 172.16.255.0/30 [20/0] via 10.1.255.1, 00:31:19
B 172.16.3.0/27 [20/0] via 10.1.255.1, 00:30:49 (仅能收到这两条BGP路由)
10.0.0.0/30 is subnetted, 1 subnets
C 10.1.255.0 is directly connected, Serial1/0 |
A:把之前的ip prefix-list NO 掉,再到R2上配置:
R2(config)#ip prefix-list set_filter seq 1 permit 172.16.0.0/22 ge 26
R2(config)#ip prefix-list set_filter seq 2 permit 172.16.255.0/30
R2(config)#router bgp 64512
R2(config-router)#nei 10.1.255.2 prefix-list set_filter out |
R3#sh ip route
………………
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 3 subnets, 3 masks
B 172.16.255.0/30 [20/0] via 10.1.255.1, 01:35:15
B 172.16.2.0/26 [20/0] via 10.1.255.1, 00:07:05
B 172.16.3.0/27 [20/0] via 10.1.255.1, 01:34:44
10.0.0.0/30 is subnetted, 1 subnets
C 10.1.255.0 is directly connected, Serial1/0 |
A:把之前的ip prefix-list NO掉,在R2上重新配置:
R2(config)#ip prefix-list set_filter seq 1 per 172.16.0.0/22 le 25
R2(config)#ip prefix-list set_filter seq 2 permit 172.16.255.0/30
R2(config)#router bgp 64512
R2(config-router)#nei 10.1.255.2 prefix-list set_filter out |
R3#clear ip bgp * soft
R3#sh ip route
………………
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 3 subnets, 3 masks
B 172.16.255.0/30 [20/0] via 10.1.255.1, 02:27:57
B 172.16.0.0/24 [20/0] via 10.1.255.1, 00:00:00
B 172.16.1.0/25 [20/0] via 10.1.255.1, 00:00:00
10.0.0.0/30 is subnetted, 1 subnets
C 10.1.255.0 is directly connected, Serial1/0 |
A、同样把之前的ip prefix-list NO 掉:
R2(config)#ip prefix-list set_filter seq 1 per 172.16.0.0/22 ge 25 le 26
R2(config)#ip prefix-list set_filter seq 2 permit 172.16.255.0/30
R2(config)#router bgp 64512
R2(config-router)#nei 10.1.255.2 prefix-list set_filter out |
R3#sh ip route
………………
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 3 subnets, 3 masks
B 172.16.255.0/30 [20/0] via 10.1.255.1, 02:34:54
B 172.16.1.0/25 [20/0] via 10.1.255.1, 00:06:57
B 172.16.2.0/26 [20/0] via 10.1.255.1, 00:00:00
10.0.0.0/30 is subnetted, 1 subnets
C 10.1.255.0 is directly connected, Serial1/0 |