1. 程式人生 > >BGP的選路

BGP的選路

BGP 選路

技術分享圖片

一、實驗要求:
1、AS1去AS2走R2
2、AS2去AS1走R4
3、AS1去AS3走R6
4、AS2去AS3走R6
5、AS3去AS2走R5
6、AS3去AS1走R5
7、每個選路規則只能使用一次
解決以上步驟的選路方法(事先沒有規劃):
1、local-preference
2、MED
3、Weight
4、Origin
5、AS-path
6、next-hop

二、BGP的選路規則:
1、weight,範圍0-65535,默認為0或32768,大優;
2、Local-preference,範圍0-65535,大優;
3、本地起源,起源與本地最優先;
4、As-path,經過AS的數量越少越憂,並且EBGP鄰居可添加AS的數量;

5、起源碼小憂,i-igp=0,e-egp=1,?-incomplete=2;
6、MED,小優;
7、EBGP路由優於IBGP路由,聯邦EBGP與普通IBGP不能使用該條進行比較,此時聯邦EBGP路由與IBGP相同;
8、最近的IGP鄰居,iIGP的metric最小的優;
9、如果配置了maximum-path [ibgp]n,如果存在多條等價路徑,會同時加載到路由表;
10、最老的路由,前提必須是external路由,聯邦內的EBGP路由當做IBGP 處理;
11、最小的router-id優;
12、多條路徑的router-id相同,那麽選擇cluster-list長度最短的;
13、BGP優選來自最低鄰居IP地址的路由,BGP neighbor配置的那個IP地址。

三、配置:

R1#sho run | s pre
ip prefix-list AS2 seq 5 permit 3.3.3.0/24
ip prefix-list AS2 seq 10 permit 4.4.4.0/24
route-map AS2 permit 10
match ip address prefix-list AS2
set local-preference 80 //解決第一步是用的是local-preference

R1#sho run | s bgp
router bgp 1
bgp log-neighbor-changes
network 1.1.1.0 mask 255.255.255.0

network 1.1.1.1 mask 255.255.255.255
neighbor 2.2.2.2 remote-as 1
neighbor 2.2.2.2 update-source Loopback0
neighbor 2.2.2.2 next-hop-self
neighbor 100.1.13.3 remote-as 2
neighbor 100.1.13.3 route-map AS2 in

技術分享圖片

R2#sho run | s pre
ip prefix-list AS3 seq 5 permit 6.6.6.0/24
ip prefix-list AS3 seq 10 permit 7.7.7.0/24
ip prefix-list AS3 seq 15 permit 5.5.5.0/24
route-map AS3 permit 10
match ip address prefix-list AS3
set weight 10 //解決第三步用的是weight

R2#sho run | s bgp
router bgp 1
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 1.1.1.1 next-hop-self
neighbor 100.1.24.4 remote-as 2
neighbor 100.1.25.5 remote-as 3
neighbor 100.1.26.6 remote-as 3
neighbor 100.1.26.6 route-map AS3 in

技術分享圖片

R3#sho run | s pre
ip prefix-list AS1 seq 5 permit 1.1.1.0/24
ip prefix-list AS1 seq 10 permit 2.2.2.0/24
route-map AS1 permit 10
match ip address prefix-list AS1
set metric 100 //解決第二步用的是MED

R3#sho run | s bgp
router bgp 2
bgp log-neighbor-changes
network 3.3.3.0 mask 255.255.255.0
neighbor 4.4.4.4 remote-as 2
neighbor 4.4.4.4 update-source Loopback0
neighbor 4.4.4.4 next-hop-self
neighbor 100.1.13.1 remote-as 1
neighbor 100.1.13.1 route-map AS1 in

技術分享圖片

R4#sho run | s pre
ip prefix-list AS3 seq 5 permit 5.5.5.0/24
ip prefix-list AS3 seq 10 permit 6.6.6.0/24
ip prefix-list AS3 seq 15 permit 7.7.7.0/24
route-map AS3 permit 10
match ip address prefix-list AS3
set origin incomplete //解決第四步用的是origin

R4#sho run | s bgp
router bgp 2
bgp log-neighbor-changes
network 4.4.4.0 mask 255.255.255.0
neighbor 3.3.3.3 remote-as 2
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 100.1.24.2 remote-as 1
neighbor 100.1.45.5 remote-as 3
neighbor 100.1.45.5 route-map AS3 in
neighbor 100.1.46.6 remote-as 3

技術分享圖片

R5#sho run | s bgp
router bgp 3
bgp log-neighbor-changes
network 5.5.5.0 mask 255.255.255.0
neighbor 6.6.6.6 remote-as 3
neighbor 6.6.6.6 update-source Loopback0
neighbor 6.6.6.6 next-hop-self
neighbor 7.7.7.7 remote-as 3
neighbor 7.7.7.7 update-source Loopback0
neighbor 7.7.7.7 next-hop-self
neighbor 100.1.25.2 remote-as 1
neighbor 100.1.45.4 remote-as 2

技術分享圖片

R6#sho run | s prefix-list AS1
ip prefix-list AS1 seq 5 permit 1.1.1.0/24
ip prefix-list AS1 seq 10 permit 2.2.2.0/24
route-map AS1 permit 10
match ip address prefix-list AS1
set as-path prepend 1 //第五步用的是as-path

R6#sho run | s prefix-list AS2
ip prefix-list AS2 seq 5 permit 3.3.3.0/24
ip prefix-list AS2 seq 10 permit 4.4.4.0/24
route-map AS2 permit 10
match ip address prefix-list AS2
set ip next-hop 5.5.5.5 //第六步用的是next-hop

R6#SHO run | s bgp
router bgp 3
bgp log-neighbor-changes
network 6.6.6.0 mask 255.255.255.0
neighbor 5.5.5.5 remote-as 3
neighbor 5.5.5.5 update-source Loopback0
neighbor 5.5.5.5 next-hop-self
neighbor 7.7.7.7 remote-as 3
neighbor 7.7.7.7 update-source Loopback0
neighbor 7.7.7.7 next-hop-self
neighbor 100.1.26.2 remote-as 1
neighbor 100.1.26.2 route-map AS1 in
neighbor 100.1.46.4 remote-as 2
neighbor 100.1.46.4 route-map AS2 in

技術分享圖片

//在第六步,R6去AS2,沒有使用next-hop時,加表並優的是R4,加表不優的是R5,由於使用了next-hop,
加表並優的路由變成R5,所以才會看到BGP表中R6去AS2的優和不優的加表路由都成了R5。但實驗結果能過達到要求。

R6#traceroute 3.3.3.3 source 6.6.6.6 numeric
Type escape sequence to abort.
Tracing the route to 3.3.3.3
VRF info: (vrf in name/id, vrf out name/id)
1 100.1.56.5 0 msec 1 msec 0 msec
2 100.1.45.4 0 msec 1 msec 0 msec
3 100.1.34.3 1 msec * 1 msec
//測驗結果正確,能滿足第六步要求

R7#sho run | s bgp
router bgp 3
bgp log-neighbor-changes
network 7.7.7.0 mask 255.255.255.0
neighbor 5.5.5.5 remote-as 3
neighbor 5.5.5.5 update-source Loopback0
neighbor 5.5.5.5 next-hop-self
neighbor 6.6.6.6 remote-as 3
neighbor 6.6.6.6 update-source Loopback0
neighbor 6.6.6.6 next-hop-self

技術分享圖片

註意:
本實驗的第六步選路方案雖實現了要求,但選路方案並不佳。所以,實驗前應對實驗中所要用到的選路規則進行推演,以便選出最好的選路方案。

BGP的選路