CCNP知识:边界网关协议(BGP)改变权重影响路径选择
今天来介绍一个比较复杂的CCNP知识,以4个路由器组成一个环形网来做为实例。边界网关协议(BGP)选择最佳路径总共有11个步骤,平常我们用的最多的大概是AS PATH路径属性,在没有改变其他路径属性的情况下,经过的AS越少,其路径越优。11个步骤有一个前提就是下一跳可达。如果这个前提不满足后面的路径属性也无从谈起。
这11步如下:
1.wights(权重),越大越好。只影响本路由器。
2.本地优先级,越大越好。影响本as内路由器。
3.本地注入的路由,本地注入的路由优于通过IBGP/EBGP获悉的路由。
4.AS PATH越小越好。
5.ORIGIN(始发地),igp>egp>?
6.MED值,越小越好。
7.邻居类型。ebgp优于ibgp。
8.前往下一跳的igp度量值。越小越好。
9.最先知道的ebgp路由。
10.邻居的bgp rid最小
11.邻居的ip地址最小。
比较难记的东西,一般经过前8个步骤就可以选出最佳路由了。而今天这个实验正是通过改变第一路径属性-权重来改变最佳路径的选择。
拓扑图如下:
下面是4个路由器的具体的配置命令:
r1属于as1,r2属于as3,r3属于as2,r4属于as4.
- r1:
- in e1/1
- ip add 192.168.1.1 255.255.255.0
- no sh
- in e1/2
- ip add 192.168.2.1 255.255.255.0
- no sh
- in loop 1
- ip add 1.1.1.1 255.0.0.0
- ip route 3.0.0.0 255.0.0.0 192.168.1.2
- router bgp 1
- nei 3.3.3.3 remote-as 2
- nei 3.3.3.3 update-source loop 1
- nei 3.3.3.3 ebgp-mutlihop 2
- nei 3.3.3.3 route-map setweight in
- nei 192.168.2.2 remote-as 3
- ip prefix-list gor3 permit 10.0.0.0/8
- http://www.xiaoxiongboke.com
- route-map setweight permit 10
- match ip add prefix-list gor3
- set weight 200
- route-map setweight permit 20
- r2:
- in e1/2
- ip add 192.168.2.2 255.255.255.0
- no sh
- in e1/3
- ip add 192.168.4.1 255.255.255.0
- no sh
- router bgp 3
- nei 192.168.2.1 remote-as 1
- nei 192.168.4.2 remote-as 4
- r3:
- in e1/1
- ip add 192.168.1.2 255.255.255.0
- no sh
- in e1/0
- ip add 192.168.3.1 255.255.255.0
- no sh
- in loop 1
- ip add 3.3.3.3 255.0.0.0
- ip route 1.0.0.0 255.0.0.0 192.168.1.1
- router bgp 2
- nei 1.1.1.1 remote-as 1
- nei 1.1.1.1 update-source loop 1
- nei 1.1.1.1 ebgp-mutlihop 2
- nei 192.168.3.2 remote-as 4
- r4:
- in e1/1
- ip add 192.168.3.2 255.255.255.0
- no sh
- in e1/2
- ip add 192.168.4.2 255.255.255.0
- in loop 1
- ip add 10.143.132.1 255.0.0.0
- router bgp 4
- nei 192.168.3.1 remote-as 2
- nei 192.168.4.1 remote-as 3
- net 10.0.0.0
记住想要使这种改变生效,必须得重置邻居关系,在这里我使用软重置。切忌在生产环境中使用硬重置,这会导致所有邻居关系中断并重新计算路由,这在有数十万条路由条目的路由器上绝对会是个灾难,没有一个小时以上的时间路由绝对不会收敛。
我们先看看在重置以前选择的最佳路由是经过哪里。
- R1#show ip bgp
- BGP table version is 5, 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.0.0.0 3.3.3.3 0 2 4 i
- *> 192.168.2.2 0 3 4 i
有些东西我得解释一下,第一列的*>代表去往10.0.0.0网段选择的最佳路径是经过下一跳为192.168.2.2的r2路由器。我们看到weight都为0,并且as path经过的数量都一样,都为2个。而路由表也体现了这一点。
- R1#show ip ro
- 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
- C 1.0.0.0/8 is directly connected, Loopback1
- S 3.0.0.0/8 [1/0] via 192.168.1.2
- B 10.0.0.0/8 [20/0] via 192.168.2.2, 00:00:49
- C 192.168.1.0/24 is directly connected, Ethernet1/1
- C 192.168.2.0/24 is directly connected, Ethernet1/2
注意,我软重置邻居关系。这条命令是在特权模式下打的,而不是在配置模式下。
clear ip bgp * soft
现在再看看选择的最佳路由变了。
- R1#clear ip bgp * soft
- R1#show ip bgp
- BGP table version is 6, 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.0.0.0 3.3.3.3 200 2 4 i
- * 192.168.2.2 0 3 4 i
现在选择的最佳路由为下一跳为3.3.3.3的r3路由器,而这条路由的weight值也变为我在路由映射表中设置的200了。
最后再看看路由表。
- R1#show ip ro
- 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
- C 1.0.0.0/8 is directly connected, Loopback1
- S 3.0.0.0/8 [1/0] via 192.168.1.2
- B 10.0.0.0/8 [20/0] via 3.3.3.3, 00:02:55
- C 192.168.1.0/24 is directly connected, Ethernet1/1
- C 192.168.2.0/24 is directly connected, Ethernet1/2
呵呵,可能有点晕。不过这些都是CCNP认证考试的必须熟悉和掌握的基础知识了,多花点时间和精力在上面,一定会有很多收获的。