Option2的圖還是使用上面的,並且R2f1/0和R4fa1/0,R5fa1/0和R7fa1/0shu。
Option2的思路是在R4與R5之間建立BGP。
但之前有一個問題,R4有路由嗎?顯然是沒有的。
因爲沒有明確的導入導出(我也沒有配置VRF),解決:
R4(config-router)#no bgp default route-target filter
R4#show ip bgp ***v4 all
BGP table version is 3, local router ID is 4.4.4.4
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
Route Distinguisher: 10:2
*>i1.1.1.1/32 2.2.2.2 11 100 0 ?
*>i12.12.12.0/24 2.2.2.2 0 100 0 ?
R4(config)#router bgp 10
R4(config-router)#nei 45.45.45.5 remote 20
R4(config-router)#address-family ***v4
R4(config-router-af)#nei 45.45.45.5 ac
鄰居關係建立了,查看R4上的BGP表:
R4#show ip bgp ***v4 all
Route Distinguisher: 10:2
*>i1.1.1.1/32 2.2.2.2 11 100 0 ?
*>i12.12.12.0/24 2.2.2.2 0 100 0 ?
Route Distinguisher: 10:7
*> 8.8.8.8/32 45.45.45.5 0 20 ?
*> 78.78.78.0/24 45.45.45.5 0 20 ?
然後再查看R3的路由表:
R3#show ip bgp ***v4 all
Route Distinguisher: 10:2
*>i1.1.1.1/32 2.2.2.2 11 100 0 ?
*>i12.12.12.0/24 2.2.2.2 0 100 0 ?
Route Distinguisher: 10:7
* i8.8.8.8/32 45.45.45.5 0 100 0 20 ?
* i78.78.78.0/24 45.45.45.5 0 100 0 20 ?
路由沒有最優,爲什麼呢?因爲下一跳不可達,怎麼解決呢?
解決方法一:
R4(config-router)#address-family ***v4
R4(config-router-af)#nei 3.3.3.3 next-hop-self
再次查看R3的路由表:
R3#show ip bgp ***v4 all
Route Distinguisher: 10:2
*>i1.1.1.1/32 2.2.2.2 11 100 0 ?
*>i12.12.12.0/24 2.2.2.2 0 100 0 ?
Route Distinguisher: 10:7
*>i8.8.8.8/32 4.4.4.4 0 100 0 20 ?
*>i78.78.78.0/24 4.4.4.4 0 100 0 20 ?
已然最優,同理在R5上也要這麼配。
現在R1和R8上都學到了路由:
R1#show ip route ospf
8.0.0.0/32 is subnetted, 1 subnets
O IA 8.8.8.8 [110/11] via 12.12.12.2, 00:00:57, FastEthernet0/0
78.0.0.0/24 is subnetted, 1 subnets
O IA 78.78.78.0 [110/11] via 12.12.12.2, 00:00:57, FastEthernet0/0
R8#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O IA 1.1.1.1 [110/11] via 78.78.78.7, 00:01:20, FastEthernet0/0
12.0.0.0/24 is subnetted, 1 subnets
O IA 12.12.12.0 [110/11] via 78.78.78.7, 00:01:19, FastEthernet0/0
R1#traceroute 8.8.8.8
1 12.12.12.2 116 msec 4 msec 48 msec
2 23.23.23.3 [MPLS: Labels 301/406 Exp 0] 212 msec 184 msec 120 msec
3 34.34.34.4 [MPLS: Label 406 Exp 0] 256 msec 228 msec 128 msec
4 45.45.45.5 [MPLS: Label 505 Exp 0] 172 msec 32 msec 220 msec
5 56.56.56.6 [MPLS: Labels 601/703 Exp 0] 184 msec 96 msec 144 msec
6 78.78.78.7 [MPLS: Label 703 Exp 0] 76 msec 52 msec 112 msec
7 78.78.78.8 140 msec * 228 msec
已經通了,但是還沒有結束,這個標籤分配的問題很難理解。
首先要理解,對於MPLS ***的路由肯定是雙層標籤。
我們先看R2,R3,R4這部分:
首先R4發送一條路由***V4的路由8.8.8.8,這條路由要攜帶一個標籤。
R4#show mpls forwarding-table (省略其他的)
406 505 10:7:8.8.8.8/32 1712 Fa0/1 45.45.45.5
然後對於MBGP,由LDP分配下一跳的標籤:
R3#show mpls forwarding-table(省略其他的)
301 Pop tag 4.4.4.4/32 1280 Fa0/1 34.34.34.4
R3分配到達4.4.4.4的標籤給R2
所以R2會收到兩層標籤。
然後R2將數據包發給R3,由於第二條彈出機制,R3將上層標籤彈出將數據包發給R4,到達R4的時候只有一層標籤,此時R4將406標籤改成505發出去。
這裏有疑問:爲什麼對於8.8.8.8的路由底層標籤會改變呢?
爲什麼要標籤,因爲R4,R5都沒有8.8.8.8的路由,如果接收到IP報頭,那就丟棄了。
然後這個標籤是由MPLS給的,因爲我沒有在接口開啓LDP。
因爲這條路由的下一跳在改變,而不是固定的R7的lo0地址,所以上層標籤被去除。
而R4只能通過改變標籤將數據包轉發給R5。
在R5同理了,由R7給一個8.8.8.8路由的標籤和R6給的下一跳的標籤。
R5#show mpls forwarding-table
502 601 7.7.7.7/32 0 Fa0/1 56.56.56.6
505 703 10:7:8.8.8.8/32 2212 Fa0/1 56.56.56.6
後面略。
解決方法二:
當然Option2還有一個現象:
R4#show ip route 45.0.0.0
C 45.45.45.5/32 is directly connected, FastEthernet0/1
C 45.45.45.0/24 is directly connected, FastEthernet0/1
R5#show ip route 45.0.0.0
C 45.45.45.4/32 is directly connected, FastEthernet0/0
C 45.45.45.0/24 is directly connected, FastEthernet0/0
產生了對面的/32位路由。
爲什麼會產生這條/32路由呢?
因爲R4將數據包發給下一跳45.45.45.5匹配45.45.45.0網段,它的標籤可能就不是什麼505而是untag了,R5收到的就不是標籤而是IP報頭了。
注意,這前面雖然是C,但是不是物理接口,是一條路由。
如果在R5上network 45.45.45.4 0.0.0.0 a 0,在R6上是學不到的,如果要學到,只能通過redistribute connected了。
這就提供了一種方式,我可以通過redistirbute 這條路由進OSPF讓R3和R6學到:
R4(config)#ip prefix-list cisco permit 45.45.45.5/32
R4(config)#route-map cisco permit 10
R4(config-route-map)#match ip address pre cisco
R4(config)#router ospf 1
R4(config-router)#redistribute connected route-map cisco subnets
R3#show ip bgp ***v4 all
Route Distinguisher: 10:2
*>i1.1.1.1/32 2.2.2.2 11 100 0 ?
*>i12.12.12.0/24 2.2.2.2 0 100 0 ?
Route Distinguisher: 10:7
*>i8.8.8.8/32 45.45.45.5 0 100 0 20 ?
*>i78.78.78.0/24 45.45.45.5 0 100 0 20 ?
下一跳已經可達了,現在試着traceroute一下:
在traceroute之前我們分析一下,在之前那種方法,下一跳改變3次,所以底層標籤改變3次,現在使用重分發路由的方法,那麼底層標籤會改變幾次?
下一跳改變兩次,應該標籤會改變兩次吧!
R1#traceroute 8.8.8.8
1 12.12.12.2 96 msec 120 msec 24 msec
2 23.23.23.3 [MPLS: Labels 302/504 Exp 0] 212 msec 48 msec 164 msec
3 34.34.34.4 [MPLS: Labels 400/504 Exp 0] 152 msec 152 msec 64 msec
4 45.45.45.5 [MPLS: Label 504 Exp 0] 92 msec 32 msec 68 msec
5 56.56.56.6 [MPLS: Labels 600/703 Exp 0] 68 msec 120 msec 32 msec
6 78.78.78.7 [MPLS: Label 703 Exp 0] 108 msec 156 msec 180 msec
的確是這樣!