本產品的文件集力求使用無偏見用語。針對本文件集的目的,無偏見係定義為未根據年齡、身心障礙、性別、種族身分、民族身分、性別傾向、社會經濟地位及交織性表示歧視的用語。由於本產品軟體使用者介面中硬式編碼的語言、根據 RFP 文件使用的語言,或引用第三方產品的語言,因此本文件中可能會出現例外狀況。深入瞭解思科如何使用包容性用語。
思科已使用電腦和人工技術翻譯本文件,讓全世界的使用者能夠以自己的語言理解支援內容。請注意,即使是最佳機器翻譯,也不如專業譯者翻譯的內容準確。Cisco Systems, Inc. 對這些翻譯的準確度概不負責,並建議一律查看原始英文文件(提供連結)。
本檔案介紹Cisco路由器上開放最短路徑優先(OSPF)到邊界閘道通訊協定(BGP)重新分配的行為。
Cisco建議您在使用本文檔之前瞭解OSPF路由型別。
本文件所述內容不限於特定軟體和硬體版本。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
本技術說明解釋思科路由器上OSPF到BGP重分發的行為。RFC 1403中概述了OSPF到BGP重分發的行為。OSPF路由有幾種型別:
區域內路由 — 在多區域OSPF網路中,來自某一區域的路由被同一區域內的路由器視為區域內路由。這些路由在
命令輸出。show ip route
區域間 — 當路由通過OSPF區域邊界路由器(ABR)時,該路由稱為OSPF區域間路由。這些路由在
命令輸出。show ip route
區域內路由和區域間路由也稱為OSPF內部路由,因為它們由OSPF自身在介面被OSPF覆蓋時生成
指令。network
External Type-2或External Type-1 — 重新分發到OSPF的路由(如已連線、靜態或其他路由協定)稱為External Type-2或External Type-1。這些路由在
命令輸出。show ip route
NSSA External Type-2或NSSA External Type 1 — 將某個區域配置為非末節區域(NSSA)並將路由重分發到OSPF時,這些路由稱為NSSA External Type-2或NSSA External Type-1。這些路由在
命令輸出。show ip route
解釋外部和NSSA第2類或1類之間的差異超出本文檔的範圍 — 有關詳細資訊,請參閱OSPF設計手冊。
預設行為是不將任何路由從OSPF重分發到BGP。必須配置重分發。您可以使用
命令在OSPF到BGP重分發期間過濾路由。要完成重分發,特定關鍵字 route-map
和 internal
, external
,
需要重新分發各自的路由。nssa-external
下面討論四種將OSPF路由重分發到BGP的情況。網路圖適用於前三種情況。第四個情況的圖和設定可在將OSPF NSSA外部路由重分配到BGP部分找到。
如果將OSPF重分發到BGP而不使用關鍵字,則預設情況下僅將OSPF區域內路由和區域間路由重分發到BGP。您可以使用
關鍵字以及internal
命令下 redistribute
重分發OSPF區域內和區域間路由。 router bgp
此配置是路由器B的新配置,它只將區域內路由(10.108.2.0/24)和區域間路由(10.108.1.0/24)重分發到BGP,並且只將OSPF內部(區域內和區域間)路由重分發到BGP:
RTB |
---|
hostname RTB ! |
路由器B僅重新分配OSPF內部路由:
RTB#show ip bgp BGP table version is 12, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.2.2.0/24 0.0.0.0 0 32768 ? *> 10.108.1.0/24 10.2.2.2 3 32768 ? *> 10.108.2.0/24 10.2.2.2 2 32768 ? RTB#
路由器C從BGP獲知這些路由:
RTC#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks B 10.2.2.0/24 [20/0] via 10.3.3.1, 00:07:07 C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.2/32 is directly connected, GigabitEthernet0/0 B 10.108.1.0/24 [20/3] via 10.3.3.1, 00:07:07 B 10.108.2.0/24 [20/2] via 10.3.3.1, 00:07:07 RTC# RTC#show ip bgp BGP table version is 8, local router ID is 10.3.3.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.2.2.0/24 10.3.3.1 0 0 100 ? *> 10.108.1.0/24 10.3.3.1 3 0 100 ? *> 10.108.2.0/24 10.3.3.1 2 0 100 ? RTC#
使用
關鍵字以及external
命令下 redistribute
將OSPF外部路由重分發到BGP。使用 router bgp
關鍵字,您有三種選擇:external
重新分發外部型別1和型別2(預設)
Redistribute型別1
Redistribute型別2
按如下所述在配置模式下輸入命令:
RTB(config-router)#router bgp 100 RTB(config-router)#redistribute ospf 1 match external
在路由器B的此配置中,僅重分發OSPF外部路由,但第1類和第2類均如此:
RTB |
---|
|
註:配置顯示
輸入的命令是 match external 1 external 2
. 這是正常現象,因為OSPF會自動附加 redistribute ospf 1 match external
external 1 external 2
配置。它匹配OSPF外部1路由和外部2路由,並將兩個路由重分發到BGP。
路由器B僅重新分配OSPF外部路由:
RTB#show ip bgp BGP table version is 25, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.2.2.2 20 32768 ? *> 192.168.2.0 10.2.2.2 23 32768 ? RTB#
路由器C從BGP獲知這兩條OSPF外部路由:
RTC#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.2/32 is directly connected, GigabitEthernet0/0 B 192.168.1.0/24 [20/20] via 10.3.3.1, 00:02:16 B 192.168.2.0/24 [20/23] via 10.3.3.1, 00:02:16
RTC#show ip bgp BGP table version is 21, local router ID is 10.3.3.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.3.3.1 20 0 100 ? *> 192.168.2.0 10.3.3.1 23 0 100 ? RTC#
在
命令,僅重分發OSPF External 1路由:router bgp 100
RTB(config)#
router bgp 100RTB(config-router)#
redistribute ospf 1 match external 1
使用先前的設定時,路由器B(RTB)BGP表顯示它只能將外部1路由重分配到BGP,而所有其他OSPF路由都不會重分配到BGP:
RTB#show ip bgp BGP table version is 28, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.2.0 10.2.2.2 23 32768 ? RTB#
同樣地,在下方輸入以下命令
在路由器B上,僅重分發OSPF外部2路由:router bgp 100
RTB(config)#
router bgp 100RTB(config-router)#
redistribute ospf 1 match external 2
在這種情況下,所有OSPF路由都會使用和
和internal
命令中的關鍵字 external
redistribute ospf
如路由器B配置所示:
RTB |
---|
|
再說一遍,
替換為external
配置。這是正常現象,除非您指定要重分佈到BGP中的特定外部路由。配置更改完成後,路由器B重新分發所有OSPF路由,路由器C開始從BGP獲取所有路由: external 1 external 2
RTB#show ip bgp BGP table version is 6, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.2.2.0/24 0.0.0.0 0 32768 ? *> 10.108.1.0/24 10.2.2.2 3 32768 ? *> 10.108.2.0/24 10.2.2.2 2 32768 ? *> 192.168.1.0 10.2.2.2 20 32768 ? *> 192.168.2.0 10.2.2.2 23 32768 ? RTB#
RTC#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks B 10.2.2.0/24 [20/0] via 10.3.3.1, 00:03:27 C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.2/32 is directly connected, GigabitEthernet0/0 B 10.108.1.0/24 [20/3] via 10.3.3.1, 00:03:27 B 10.108.2.0/24 [20/2] via 10.3.3.1, 00:03:27 B 192.168.1.0/24 [20/20] via 10.3.3.1, 00:03:27 B 192.168.2.0/24 [20/23] via 10.3.3.1, 00:03:27 RTC#
這是一種特殊情況,其中只有NSSA路由重新分發到BGP中。此案例與僅將OSPF外部(型別1和2)路由重分配到BGP一節中描述的情況非常相似。唯一的區別是OSPF現在匹配NSSA外部路由,而不是僅匹配外部路由。路由器B的路由表顯示了以下OSPF NSSA外部路由:
RTB#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks C 10.2.2.0/24 is directly connected, GigabitEthernet0/1 L 10.2.2.3/32 is directly connected, GigabitEthernet0/1 C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.1/32 is directly connected, GigabitEthernet0/0 O IA 10.108.1.0/24 [110/3] via 10.2.2.2, 00:05:00, GigabitEthernet0/1 O 10.108.2.0/24 [110/2] via 10.2.2.2, 00:05:00, GigabitEthernet0/1 O N2 192.168.1.0/24 [110/20] via 10.2.2.1, 00:10:14, GigabitEthernet0/1 O N1 192.168.2.0/24 [110/22] via 10.2.2.2, 00:03:43, GigabitEthernet0/1 RTB#
以下網路圖是適用於此案例的:
網路圖顯示,路由器B同時收到OSPF N1和N2路由。預設行為是重新分配N1和N2路由,如果僅
使用關鍵字。路由器B的這種配置允許我們將OSPF N2(192.168.1.0/24)和OSPF N1(192.168.2.0/24)路由重分發到BGP:nssa-external
RTB |
---|
|
注意:與OSPF外部配置類似,顯示先前的配置
輸入的命令是 match nssa-external 1 nssa-external 2
這是正常現象,因為OSPF會自動附加 redistribute ospf 1 match nssa-external
.nssa-external 1 nssa-external 2
配置。它匹配OSPF N1和OSPF N2路由,並將兩個路由重分發到BGP。
在路由器B上更改配置後,它會重新分配OSPF NSSA外部路由,而路由器C從BGP獲取OSPF NSSA外部路由:
RTB#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks C 10.2.2.0/24 is directly connected, GigabitEthernet0/1 L 10.2.2.3/32 is directly connected, GigabitEthernet0/1 C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.1/32 is directly connected, GigabitEthernet0/0 O IA 10.108.1.0/24 [110/3] via 10.2.2.2, 00:09:40, GigabitEthernet0/1 O 10.108.2.0/24 [110/2] via 10.2.2.2, 00:09:40, GigabitEthernet0/1 O N2 192.168.1.0/24 [110/20] via 10.2.2.1, 00:14:54, GigabitEthernet0/1 O N1 192.168.2.0/24 [110/22] via 10.2.2.2, 00:08:23, GigabitEthernet0/1 RTB# RTB#show ip bgp BGP table version is 17, local router ID is 10.3.3.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.2.2.1 20 32768 ? *> 192.168.2.0 10.2.2.2 22 32768 ? RTB#
RTC#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks C 10.3.3.0/24 is directly connected, GigabitEthernet0/0 L 10.3.3.2/32 is directly connected, GigabitEthernet0/0 B 192.168.1.0/24 [20/20] via 10.3.3.1, 00:01:29 B 192.168.2.0/24 [20/22] via 10.3.3.1, 00:01:29 RTC# RTC#show ip bgp BGP table version is 41, local router ID is 10.3.3.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.3.3.1 20 0 100 ? *> 192.168.2.0 10.3.3.1 22 0 100 ? RTC#
與OSPF外部路由一樣,要僅重分發OSPF N1路由,請在路由器B的路由器BGP 100下輸入以下命令:
RTB(config)#
router bgp 100
RTB(config-router)#redistribute ospf 1 match nssa-external 1
!--- This redistributes only OSPF NSSA-external Type-1 routes into BGP.
要僅重分發OSPF N2路由,請在路由器B的路由器BGP 100下輸入以下命令:
RTB(config)#
router bgp 100redistribute ospf 1 match nssa-external 2
RTB(config-router)#
!--- This redistributes only OSPF NSSA-external Type-2 routes into BGP.
注意:路由對映還可用於將OSPF型別1/2重分發到BGP。有關詳細資訊,請參閱在BGP中重分發OSPF E2路由。
瞭解連續配置更改如何改變配置非常重要。帶有match選項的新命令不會覆蓋上一個命令,但會新增到該命令中。下一個示例說明配置命令序列如何影響重分發:
R4#configure terminal R4(config)#router bgp 100 R4(config-router)#redistribute ospf 1 match internal R4(config-router)#^Z !--- Initially, you redistribute internal OSPF routes into BGP 100. R4#show run | include redistribute ospf redistribute ospf 1 match internal R4#configure terminal R4(config)#router bgp 100 R4(config-router)#redistribute ospf 1 match external R4(config-router)#^Z !--- With this second command, you tell BGP to also redistribute external OSPF routes. R4#show run | include redistribute ospf redistribute ospf 1 match internal external 1 external 2 R4# R4#configure terminal R4(config)#router bgp 100 R4(config-router)#no redistribute ospf 1 match external 2 R4(config-router)#^Z !--- With this no command, you only disable the redistribution of external type 2 into BGP.
!--- All other types of routes previously configured remain. R4#show run | include redistribute ospf redistribute ospf 1 match internal external 1 !--- As you can see, internal and external type 1 remain. R4#configure terminal R4(config)#router bgp 100 R4(config-router)#no redistribute ospf 1 match internal external 1 R4(config-router)#^Z !--- Now, with this no command, which includes all configured keywords, it is important to note that you
!--- still do not disable the redistribution fully. you only removed the keyword. After this,
!--- the IOS still acts as default—redistributing internal routes only. R4#show run | include redistribute ospf redistribute ospf 1 R4#configure terminal R4(config)#router bgp 100 R4(config-router)#no redistribute ospf 1 !--- Always use the previous command in order to completely disable redistribution. R4(config-router)# ^Z R4#show run | include redistribute ospf R4#
路由重分發用於將通過使用一種協定獲知的路由傳播到另一種路由協定中。將BGP重新分發到IGP中時,只有eBGP獲知的路由會重新分發。內部邊界網關協定(iBGP)在路由器上獲知的路由不會引入到IGP中,以防止產生路由環路。
預設情況下,iBGP重分發到IGP是禁用的。發出
命令,以便將iBGP路由重分發到IGP。需要採取預防措施,才能使用路由對映將特定路由重分配到IGP中。bgp redistribute-internal
將iBGP路由重分發到OSPF的示例配置如下所示:
Router(config)#router bgp 65345 Router(config-router)#bgp redistribute-internal ! Router(config)#router ospf 100 Router(config-router)#redistribute bgp 65345 subnets
注意:將iBGP路由重新分發到內部網關協定可能導致自治系統(AS)中的路由環路。不建議這樣做。需要設定路由過濾器以控制匯入IGP中的資訊。
若要將預設路由重分發到BGP,請使用
宣告和network
. 在此示例中,OSPF預設路由被重分佈到BGP中。這可以通過建立路由對映和分配預設網路(標準ACL允許)來完成。 default-information originate
! route-map map_default_only permit 10 match ip address acl_default_only ! ip access-list standard acl_default_only permit 0.0.0.0 ! router bgp 64601 network 0.0.0.0 redistribute ospf 1 route-map map_default_only default-information originate !
!--- Distributes the default route in bgp
設定後,使用
指令。 clear ip bgp *
修訂 | 發佈日期 | 意見 |
---|---|---|
1.0 |
11-Oct-2001 |
初始版本 |