CCNP-35 BGP 5
实验拓扑: 实验要求:按照拓扑将 4 台路由器分别配置在 AS 100/200 中, R1 与 R2 R3 成为 EBGP PEER , R4 与 R2 R3 成为 IBGP PEER ,在 R4 上起 loopback 接口,配置完成后在 R1 上观察 BGP 路由表,看看 R4 的 loopback 接口的网络是通过哪台路由器学习到的,然后通过修改 weight 属性,使之从另外一台路由器学习 R4 的 loopback 网络。
试验目的:掌握 BGP 选路时 weight 属性的用法和配置方法。
实验配置:
R1 :
R1(config)#int f0/0
R1(config-if)#ip add 172.16.1.1 255.255.255.0
R1(config-if)#no shu
R1(config-if)#exit
R1(config)#int f1/0
R1(config-if)#ip add 172.16.4.1 255.255.255.0
R1(config-if)#no shu
R1(config-if)#exit
R1(config)#int loop0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#exit
R1(config)#router bgp 100
R1(config-router)#neighbor 172.16.1.2 remote-as 200
R1(config-router)#neighbor 172.16.4.2 remote-as 200
R1(config-router)#exit
R2 :
R2(config)#int f0/0
R2(config-if)#ip add 172.16.1.2 255.255.255.0
R2(config-if)#no shu
R2(config-if)#exit
R2(config)#int f1/0
R2(config-if)#ip add 172.16.2.1 255.255.255.0
R2(config-if)#no shu
R2(config-if)#exit
R2(config)#int loop0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config-if)#exit
R2(config)#router ospf 100
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 0.0.0.0 0.0.0.0 a 0
R2(config-router)#exit
R2(config)#router bgp 200
R2(config-router)#neighbor 4.4.4.4 remote-as 200
R2(config-router)#neighbor 4.4.4.4 update-source loopback 0
R2(config-router)#neighbor 3.3.3.3 remote-as 200
R2(config-router)#neighbor 3.3.3.3 update-source loopback 0
R2(config-router)#neighbor 172.16.1.1 remote-as 100
R2(config-router)#exit
R3 :
R3(config)#int f0/0
R3(config-if)#ip add 172.16.3.2 255.255.255.0
R3(config-if)#no shu
R3(config-if)#exit
R3(config)#int f1/0
R3(config-if)#no shu
R3(config-if)#exit
R3(config)#int loop0
R3(config-if)#ip add 3.3.3.3 255.255.255.0
R3(config-if)#exit
R3(config)#router ospf 100
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 0.0.0.0 0.0.0.0 a 0
R3(config-router)#exit
R3(config)#router bgp 200
R3(config-router)#neighbor 2.2.2.2 remote-as 200
R3(config-router)#neighbor 2.2.2.2 update-source loopback 0
R3(config-router)#neighbor 4.4.4.4 remote-as 200
R3(config-router)#neighbor 4.4.4.4 update-source loopback 0
R3(config-router)#neighbor 172.16.4.1 remote-as 100
R3(config-router)#exit
R4 :
R4(config)#int f1/0
R4(config-if)#ip add 172.16.2.2 255.255.255.0
R4(config-if)#no shu
R4(config-if)#exit
R4(config)#int f0/0
R4(config-if)#ip add 172.16.3.1 255.255.255.0
R4(config-if)#no shu
R4(config-if)#exit
R4(config)#int loop0
R4(config-if)#ip add 4.4.4.4 255.255.255.0
R4(config-if)#exit
R4(config)#router ospf 100
R4(config-router)#router-id 4.4.4.4
R4(config-router)#network 0.0.0.0 0.0.0.0 a 0
R4(config-router)#exit
R4(config)#int loop1
R4(config-if)#ip add 10.10.10.10 255.255.255.0
R4(config-if)#exit
R4(config)#int loop2
R4(config-if)#ip add 20.20.20.20 255.255.255.0
R4(config-if)#exit
R4(config)#router bgp 200
R4(config-router)#neighbor 2.2.2.2 remote-as 200
R4(config-router)#neighbor 2.2.2.2 update-source loopback 0
R4(config-router)#neighbor 3.3.3.3 remote-as 200
R4(config-router)#neighbor 3.3.3.3 update-source loopback 0
R4(config-router)#network 10.10.10.0 mask 255.255.255.0
R4(config-router)#network 20.20.20.0 mask 255.255.255.0
R4(config-router)#exit
好了,基本的 BGP 配置完成了,下面我们到 R1 上 show ip bgp 查看一下 BGP 路由表:
R1#show ip bgp
BGP table version is 3, local router ID is 1.1.1.1
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
* 10.10.10.0/24 172.16.4.2 0 200 i
*> 172.16.1.2 0 200 i
* 20.20.20.0/24 172.16.4.2 0 200 i
*> 172.16.1.2 0 200 i
10 和 20 的路由都是从 172.16.1.2 学到的,也就是从 R2 学到的,默认的 weight 为 0 ,因为这条路由不是由自己产生的(如果是自己产生的路由,默认为 32768 ,再 R4 上 show ip bgp 看到的就会是 32768 )。
下面我们在 R1 上修改 BGP 的 weight 属性,使 10 的路由从 R1 走, 20 的路由从 R2 走:
R1(config)#access-list 10 permit 10.10.10.0 0.0.0.255
R1(config)#access-list 20 permit 20.20.20.0 0.0.0.255
R1(config)#route-map wei_10 permit 10
R1(config-route-map)#match ip add 10
R1(config-route-map)#set weight 65535
R1(config-route-map)#exit
R1(config)#route-map wei_10 permit 20
R1(config-route-map)#set weight 32768
R1(config-route-map)#exit
R1(config)#route-map wei_20 permit 10
R1(config-route-map)#match ip add 20
R1(config-route-map)#set weight 65535
R1(config-route-map)#exit
R1(config)#route-map wei_20 permit 20
R1(config-route-map)#set weight 32768
R1(config-route-map)#exit
R1(config)#router bgp 100
R1(config-router)#neighbor 172.16.1.2 route-map wei_10 in
R1(config-router)#neighbor 172.16.4.2 route-map wei_20 in
R1(config-router)#exit
上面的配置很关键,首先需要定义 ACL ,用来标记需要使用策略的路由,然后配置策略路由,匹配刚才定义的感兴趣的路由,最后分别应用到两个邻居上,注意方向为 in ( weight 属性本地有效), BGP 会优先选择 weight 值大的路径 。下面我把有关定义 10 路由的配置详细讲解一下: R1(config)#access-list 10 permit 10.10.10.0 0.0.0.255 // 定义 10.10.10.0/24 位感兴趣的路由
R1(config)#route-map wei_10 permit 10 // 配置策略路由 wei_10 ,序号为 10 ,允许通过。
R1(config-route-map)#match ip add 10 // 匹配 ACL 10 定义的路由
R1(config-route-map)#set weight 65535 // 设置 weight 为 65535
R1(config-route-map)#exit
R1(config)#route-map wei_10 permit 20 // 配置策略路由 wei_10 ,序号为 20 ,允许通过。
R1(config-route-map)#set weight 32768 // 刚才没有匹配 ACL 10 的路由的 weight 设置为 32768
R1(config-route-map)#exit
R1(config)#router bgp 100
R1(config-router)#neighbor 172.16.1.2 route-map wei_10 in // 在邻居 172.16.1.2 上应用策略路由 wei_10
这样配置完成后,我们先在 R1 上 clear ip bgp * ,然后再来看看 R1 的 BGP 路由表:
R1#show ip bgp
BGP table version is 3, local router ID is 1.1.1.1
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
* 10.10.10.0/24 172.16.4.2 32768 200 i
*> 172.16.1.2 65535 200 i
*> 20.20.20.0/24 172.16.4.2 65535 200 i
* 172.16.1.2 32768 200 i
看到了吗?不仅原来默认的 weight 属性值都发生了变化,并且也改变了 20 这个路由的下一跳为 172.16.4.2 ,也就是 R3 了,成功地实现了用 weight 属性来修改 BGP 的选路。再来看一下 R1 的路由表:
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
20.0.0.0/24 is subnetted, 1 subnets
B 20.20.20.0 [20/0] via 172.16.4.2, 00:00:26
172.16.0.0/24 is subnetted, 2 subnets
C 172.16.4.0 is directly connected, FastEthernet1/0
C 172.16.1.0 is directly connected, FastEthernet0/0
10.0.0.0/24 is subnetted, 1 subnets
B 10.10.10.0 [20/0] via 172.16.1.2, 00:00:26
实验总结:掌握 weight 属性值的大小对 BGP 路径选择的影响,还要掌握其配置方法。
本文转自loveme2351CTO博客,原文链接: http://blog.51cto.com/loveme23/54589 ,如需转载请自行联系原作者