此产品的文档集力求使用非歧视性语言。在本文档集中,非歧视性语言是指不隐含针对年龄、残障、性别、种族身份、族群身份、性取向、社会经济地位和交叉性的歧视的语言。由于产品软件的用户界面中使用的硬编码语言、基于 RFP 文档使用的语言或引用的第三方产品使用的语言,文档中可能无法确保完全使用非歧视性语言。 深入了解思科如何使用包容性语言。
思科采用人工翻译与机器翻译相结合的方式将此文档翻译成不同语言,希望全球的用户都能通过各自的语言得到支持性的内容。 请注意:即使是最好的机器翻译,其准确度也不及专业翻译人员的水平。 Cisco Systems, Inc. 对于翻译的准确性不承担任何责任,并建议您总是参考英文原始文档(已提供链接)。
本文档介绍思科路由器上开放最短路径优先(OSPF)到边界网关协议(BGP)重分发的行为。
Cisco建议您先了解OSPF路由类型,然后再使用本文档。
本文档不限于特定的软件和硬件版本。
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您的网络处于活动状态,请确保您了解所有命令的潜在影响。
有关文档规则的详细信息,请参阅 Cisco 技术提示规则。
本技术说明解释思科路由器上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的路由(例如Connected、Static或其他路由协议)称为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。这些路由在路由表中标记为O N2或O N1
命令输出.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
此配置是仅将区域内路由 (10.108.2.0/24) 和区域间路由 (10.108.1.0/24) 重分配到 BGP 中的路由器 B 的新配置,并且只会将 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(默认)
重新分发类型1
重新分发类型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路由都使用这两者重分发到BGP
和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
配置后,清除与的bgp会话
命令。 clear ip bgp *
版本 | 发布日期 | 备注 |
---|---|---|
1.0 |
11-Oct-2001 |
初始版本 |