本文件說明思科路由器將開放最短路徑優先 (OSPF) 重新分配至邊界閘道協定 (BGP) 的行為。
使用本文檔之前,思科建議您瞭解OSPF路由型別、BGP基礎知識和路由重分發。
本文件所述內容不限於特定軟體和硬體版本。
附註:本檔案中的範例使用Cisco IOS軟體命令語法。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
本技術說明解釋思科路由器上OSPF到BGP重分發的行為。RFC 1403文檔了OSPF和BGP之間互動的歷史指南。
OSPF路由有幾種型別:
區域內 — 在多區域OSPF網路中,來自某一區域的路由被同一區域中的路由器視為區域內路由。在show ip route 命令輸出中,這些路由標籤為O。
區域間 — 當路由通過OSPF區域邊界路由器(ABR)時,該路由稱為OSPF區域間路由。在show ip route命令輸出中,這些路由被標籤為O IA。
區域內路由和區域間路由也稱為OSPF內部路由,因為它們代表源自OSPF域內的字首,而不是重分發到OSPF的路由。
External Type-2或External Type-1 — 重新分發到OSPF中的路由(如已連線、靜態或其他路由協定)稱為External Type-2或External Type-1。在show ip route命令輸出中,這些路由標籤為O E2或O E1。
NSSA External Type-2或NSSA External Type 1 — 將某個區域配置為非末節區域(NSSA)並將路由重分發到OSPF時,這些路由稱為NSSA External Type-2或NSSA External Type-1。在show ip route 命令輸出中,這些路由標籤為O N2或O N1。
解釋外部和NSSA第2類或1類之間的差異超出本文檔的範圍;有關詳細資訊,請參閱OSPF設計手冊。
預設行為是不將任何路由從OSPF重分發到BGP。必須配置重分發。在OSPF到BGP重分發期間,使用route-map命令過濾路由。要顯式選擇路由型別,請使用適用的match internal、match external或match nssa-external選項。如果不使用匹配選項,則預設情況下,redistribute ospf會重新分配OSPF內部路由。
本文檔討論了五個主要的OSPF到BGP重分發案例。拓撲A適用於前四種情況。拓撲B適用於「將OSPF NSSA外部路由重分配到BGP」部分中所述的NSSA外部路由案例。
將OSPF重新分發到BGP拓撲A
如果將OSPF重分發到BGP而不使用關鍵字,則預設情況下僅將OSPF區域內路由和區域間路由重分發到BGP。要重分發OSPF Intra-area和Inter-area路由,請在路由器bgp下使用internal關鍵字和redistribute命令。
此路由器B(RTB)配置將OSPF內部字首10.2.2.0/24、10.108.1.0/24和10.108.2.0/24重新分發到BGP:
| RTB |
|---|
hostname RTB ! interface GigabitEthernet0/0 ip address 10.3.3.1 255.255.255.0 duplex auto speed auto media-type rj45 ! interface GigabitEthernet0/1 ip address 10.2.2.3 255.255.255.0 duplex auto speed auto media-type rj45 |
路由器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#
若要將OSPF外部路由重分發到BGP,請在router bgp下使用帶有redistribute命令的external關鍵字。使用external關鍵字時,有三個選擇:
重新分發外部型別1和型別2(預設)
Redistribute型別1
Redistribute型別2
按如下所述在配置模式下輸入命令:
RTB(config)#router bgp 100 RTB(config-router)#redistribute ospf 1 match external
此路由器B配置僅重新分配OSPF外部路由,包括第1類路由和第2類路由:
| RTB |
|---|
hostname RTB ! interface GigabitEthernet0/0 ip address 10.3.3.1 255.255.255.0 duplex auto speed auto media-type rj45 ! interface GigabitEthernet0/1 ip address 10.2.2.3 255.255.255.0 duplex auto speed auto media-type rj45 ! router ospf 1 network 10.2.2.0 0.0.0.255 area 1 ! router bgp 100 |
路由器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外部第1類路由,請在路由器B的router bgp 100下輸入以下命令:
RTB(config)#router bgp 100
RTB(config-router)#redistribute ospf 1 match external 1
使用先前的設定,路由器B(RTB)BGP表顯示路由器B只會將外部第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#
要僅重分發OSPF外部第2類路由,請在路由器B的router bgp 100下輸入以下命令:
RTB(config)#router bgp 100
RTB(config-router)#redistribute ospf 1 match external 2
在這種情況下,OSPF內部路由以及型別1和型別2的OSPF外部路由會使用內部和外部匹配選項重新分發到BGP,如以下路由器B配置所示:
| RTB |
|---|
hostname RTB ! interface GigabitEthernet0/0 ip address 10.3.3.1 255.255.255.0 duplex auto speed auto media-type rj45 ! interface GigabitEthernet0/1 ip address 10.2.2.3 255.255.255.0 duplex auto speed auto media-type rj45 ! router ospf 1 network 10.2.2.0 0.0.0.255 area 1 ! router bgp 100 |
同樣,在配置中,external替換為external 1 external 2。這是正常現象,除非您指定要重分佈到BGP中的特定外部路由。更改配置後,路由器B會重新分配選定的內部路由和外部路由,路由器C通過BGP獲取這些路由:
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中。此案例與僅重分佈到BGP中的OSPF外部(型別1和型別2)路由一節中描述的情況非常相似。唯一的區別是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#
以下網路圖是適用於此案例的:
將OSPF重新分發到BGP拓撲B
網路圖顯示,路由器B同時收到OSPF N1和N2路由。如果僅使用nssa-external關鍵字,則預設行為是重分發N1和N2路由。此組態允許RTB將OSPF N2(192.168.1.0/24)和OSPF N1(192.168.2.0/24)路由重分發到BGP:
| RTB |
|---|
hostname RTB ! interface GigabitEthernet0/0 ip address 10.3.3.1 255.255.255.0 duplex auto speed auto media-type rj45 ! interface GigabitEthernet0/1 ip address 10.2.2.3 255.255.255.0 duplex auto speed auto media-type rj45 ! router ospf 1 |
在路由器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的router bgp 100下輸入以下命令:
RTB(config)#router bgp 100
RTB(config-router)#redistribute ospf 1 match nssa-external 2
!--- This redistributes only OSPF NSSA-external Type-2 routes into BGP.
瞭解連續配置更改如何改變配置非常重要。帶有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 !--- This no command removes all explicit match options but does not disable redistribution
!--- The remaining redistribute ospf 1 command uses the default behavior and redistributes
!--- 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 !--- Use no redistribute ospfcommand to disable OSPF-to-BGP redistribution completely. R4(config-router)# ^Z R4#show run | include redistribute ospf R4#
路由重分佈將通過一個協定獲知的路由傳播到另一個路由協定中。將BGP重分發到IGP時,預設情況下只重分發eBGP獲知的路由。路由器上已知的iBGP獲知的路由不會引入到IGP中,以防止產生路由環路。
預設情況下,iBGP重分發到IGP是禁用的。運行bgp redistribute-internal 命令以啟用iBGP路由重分配到IGP。需要採取預防措施,才能使用路由對映將特定路由重分配到IGP中。
將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獲知的路由重分發到IGP中會在自治系統內建立路由環路。僅重新分髮帶有路由對映的顯式批准的字首。
要將OSPF獲取的預設路由重分發到BGP,請在路由對映中僅允許0.0.0.0/0,將路由對映應用到OSPF重分發,並啟用使用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 redistribute ospf 1 route-map map_default_only default-information originate !
!--- Distributes the default route in bgp
network 0.0.0.0命令是單獨的發起方法,需要在路由表中提供準確的預設路由:
! router bgp 64601 network 0.0.0.0 !
設定後,使用show ip bgp 0.0.0.0驗證預設路由,並使用show ip bgp neighbors <neighbor-address> advertised-routes驗證其通告。
附註:BGP通常不重置會話就通告新路由。要請求即時、無中斷的更新交換,請運行clear ip bgp * soft命令。此命令用於保持BGP會話的建立。
| 修訂 | 發佈日期 | 意見 |
|---|---|---|
3.0 |
08-Sep-2026
|
重新認證 — 更新的SEO和格式 |
2.0 |
22-Apr-2025
|
標題、標題和格式。 |
1.0 |
11-Oct-2001
|
初始版本 |