Bgp的本地優先屬性
Router#config t
Router(config)#host R2
R2(config)#int s1/1
R2(config-if)#ip addr 202.110.101.1 255.255.255.0
R2(config-if)#encap hdlc
R2(config-if)#clock rate 56000
R2(config-if)#no shut
R2(config)#int s1/2
R2(config-if)#ip addr 202.110.104.2 255.255.255.0
R2(config-if)#exi
R2(config)#router bgp 64500
R2(config-router)#neighbor 202.110.101.2 remote-as 64500
R2(config-router)#neighbor 202.110.104.1 remote-as 64500
R2(config-router)#net 202.110.101.0
R2(config-router)#net 202.110.104.0
Router(config)#host R3
R3(config)#int s1/1
R3(config-if)#ip addr 202.110.101.2 255.255.255.0
R3(config-if)#encap hdlc
R3(config-if)#no shut
R3(config-if)#int s1/2
R3(config-if)#ip addr 202.110.102.1 255.255.255.0
R3(config-if)#clock rate 56000
R3(config-if)#exit
R3(config)#
R3(config)#router bgp 64500
R3(config-router)#neighbor 202.110.101.1 remote-as 64500
R3(config-router)#neighbor 202.110.102.2 remote-as 64501
R3(config-router)#net 202.110.101.0
R3(config-router)#net 202.110.102.0
config)#
R4(config)#int lo0
R4(config-if)#ip addr 192.168.10.1 255.255.255.0
R4(config-if)#exit
R4(config)#int s1/2
R4(config-if)#ip addr 202.110.102.2 255.255.255.0
R4(config-if)#encap hdlc
R4(config-if)#no shut
R4(config)#int s1/1
R4(config-if)#ip addr 202.110.103.1 255.255.255.0
R4(config-if)#clock rate 56000
R4(config)#router bgp 64501
R4(config-router)#neighbor 202.110.102.1 remote-as 64500
R4(config-router)#neighbor 202.110.103.2 remote-as 64500
R4(config-router)#net 192.168.10.0
R4(config-router)#net 202.110.102.0
R4(config-router)#net 202.110.103.0
Router(config)#host R5
R5(config)#int s1/1
R5(config-if)#ip addr 202.110.103.2 255.255.255.0
R5(config-if)#encap hdlc
R5(config-if)#no shut
R5(config-if)#exit
R5(config)#int
R5(config)#int s1/2
R5(config-if)#ip addr 202.110.104.1 255.255.255.0
R5(config-if)#clock rate 56000
R5(config)#router bgp 64500
R5(config-router)#neighbor 202.110.103.1 remote-as 64501
R5(config-router)#neighbor 202.110.104.2 remote
R5(config-router)#neighbor 202.110.104.2 remote-as 64500
R5(config-router)#net 202.110.103.0
R5(config-router)#net 202.110.104.0 ^
R5(config-router)#net 202.110.104.0
R5(config-router)#exit
R2上測試
R2#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 202.110.101.0/24 is directly connected, Serial1/1
B 192.168.10.0/24 [200/0] via 202.110.102.2, 00:00:20
B 202.110.102.0/24 [200/0] via 202.110.101.2, 00:18:46
B 202.110.103.0/24 [200/0] via 202.110.104.1, 00:13:38
C 202.110.104.0/24 is directly connected, Serial1/2
由R2上的路由,可以看出預設情況下學習R4上的路由走R3,下面我們将人為通過修改路由器的本地優先屬性,使R2上學習到R4的路由走R5,如果成功,那麼今天的目的就基本達到了。本地優先屬性的修改文法是:
(config-router)#bgp default local-preference 值
//該值預設範圍是0-----4294967295,預設是100,且屬性值越高越好。
我們讓R3為預設的100,人為将R5的屬性值改為120,看試驗效果。
R5(config-router)#bgp default local-preference 120
在R2上測試,
R2#clear ip ro *
B 192.168.10.0/24 [200/0] via 202.110.102.2, 00:00:01 當重新學習路由表後,該路由沒有變,不是我們想要的試驗結果。
B 202.110.102.0/24 [200/0] via 202.110.101.2, 00:00:01
B 202.110.103.0/24 [200/0] via 202.110.104.1, 00:00:01
R2#clear ip bgp *
*Apr 30 20:22:31.027: %BGP-5-ADJCHANGE: neighbor 202.110.101.2 Down User reset
*Apr 30 20:22:31.031: %BGP-5-ADJCHANGE: neighbor 202.110.104.1 Down User reset 提示重新啟動。
R2#show ip bgp
BGP table version is 8, local router ID is 202.110.104.2
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
* i192.168.10.0 202.110.102.2 0 100 0 64501 i
*>i 202.110.103.1 0 120 0 64501 I
>表示最好路由,優先屬性變成了120,
r>i202.110.101.0 202.110.101.2 0 100 0 i
* i202.110.102.0 202.110.101.2 0 100 0 i
*>i 202.110.103.1 0 120 0 64501 i
* i202.110.103.0 202.110.102.2 0 100 0 64501 i
*>i 202.110.104.1 0 120 0 i
r>i202.110.104.0 202.110.104.1 0 120 0 i
有這張bgp表可以看出明顯存在下一跳問題,也可以按照以前的修改下一跳,克服保留下一跳的問題。
分别在R3 和R5上做,因為理論上R2的下一跳應該在這兩台路由器上。
R3(config-router)#neighbor 202.110.101.1 next-hop-self
R5(config-router)#neighbor 202.110.104.2 next-hop-self
BGP table version is 12, local router ID is 202.110.104.2
* i192.168.10.0 202.110.101.2 0 100 0 64501 i
*>i 202.110.104.1 0 120 0 64501 i
*> 202.110.101.0 0.0.0.0 0 32768 i
* i 202.110.101.2 0 100 0 i
* i202.110.103.0 202.110.101.2 0 100 0 64501 i
*> 202.110.104.0 0.0.0.0 0 32768 i
* i 202.110.104.1 0 120 0 i
R2#
B 192.168.10.0/24 [200/0] via 202.110.103.1, 00:01:02 經過的路徑也改了過來。
B 202.110.102.0/24 [200/0] via 202.110.103.1, 00:01:02
B 202.110.103.0/24 [200/0] via 202.110.104.1, 00:01:02
本文轉自shenleigang 51CTO部落格,原文連結:http://blog.51cto.com/shenleigang/154602,如需轉載請自行聯系原作者