本文档介绍如何配置和验证边界网关协议 (BGP) 条件通告功能。
Cisco 建议您了解以下主题:
本文档不限于特定的软件和硬件版本。
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您的网络处于活动状态,请确保您了解所有命令的潜在影响。
边界网关协议 (BGP) 条件通告功能可以根据 BGP 表中是否存在其他前缀,提供对路由通告的更多控制。
本文档中描述的BGP条件通告功能在Cisco IOS®软件版本11.1和11.2中引入,在更高版本中可用。
通常,会传播路由,而不管是否存在不同的路径。BGP 条件通告功能使用 neighbor advertise-map 命令的 non-exist-map 和 advertise-map 关键词,目的是按路由前缀跟踪路由。如果路由前缀不出现在non-exist-map命令输出中,那就公布advertise-map命令指定的路由。此功能对于多宿主网络非常有用,在多宿主网络中,只有在来自其他提供商的信息不存在时,才会将有些前缀通告给其中一个提供商(这表示在对等会话中出现故障或出现部分可达性问题)。
除了BGP路由器发送到其对等体的正常公告之外,还发送有条件的BGP公告。
本部分提供有关如何配置本文档所述功能的信息。
注意:要查找有关本文档中所用命令的其他信息,请使用Cisco IOS命令查找工具。只有思科注册用户才能访问思科内部工具和信息。
本文档使用此图所示的网络设置。
这里,R103的环回接口用于向R102通告192.168.50.0/24。R102有一个BGP网络172.16.16.0/24,默认情况下会通告给其外部BGP(eBGP)对等体R101和R103。
网络设置
使用 BGP 条件通告功能,您现在可以在 R102 上完成以下任务:
如果192.168.50.0/24存在于R102的BGP表中,请勿将172.16.16.0/24网络通告给R101。
如果192.168.50.0/24不存在于R102的BGP表中,请向R101通告172.16.16.0/24网络。
在Cisco IOS 12.2T或更高版本中,exist-map关键字也可用于完成以下任务:
如果R102 BGP表中存在192.168.50.0/24,请向R101通告172.16.16.0/24网络。
如果192.168.50.0/24不存在于R102 BGP表中,请不要向R101通告172.16.16.0/24网络。
本文档使用以下配置:
注意:此处的示例讨论 non-exist-map 关键字。exist-map 关键字的用法与此类似。
| R102 |
|---|
hostname R102 ! interface Loopback0 ip address 172.16.16.1 255.255.255.0 ! interface Serial8/0 ip address 10.10.10.2 255.255.255.0 ! interface Serial9/0 ip address 10.10.20.2 255.255.255.0 ! router bgp 2 bgp log-neighbor-changes network 172.16.16.0 mask 255.255.255.0 network 172.31.130.0 neighbor 10.10.10.1 remote-as 1 neighbor 10.10.10.1 advertise-map ADVERTISE non-exist-map NON-EXIST !--- Advertises the routes matched in the route-map ADVERTISE (172.16.16.0/24) |
| R103 |
|---|
hostname R103 ! interface Loopback0 ip address 192.168.50.1 255.255.255.0 ! interface Serial9/0 ip address 10.10.20.3 255.255.255.0 ! router bgp 3 bgp log-neighbor-changes network 192.168.50.0 neighbor 10.10.20.2 remote-as 2 ! |
| R101 |
|---|
hostname R101 ! interface Loopback0 ip address 10.200.200.1 255.255.255.0 ! interface Serial8/0 ip address 10.10.10.1 255.255.255.0 ! router bgp 1 bgp log-neighbor-changes network 10.200.200.0 neighbor 10.10.10.2 remote-as 2 ! |
此示例验证当192.168.50.0/24位于R102 BGP表中时的BGP的外观:
检查配置
首先,检查R102 BGP表中是否存在192.168.50.0/24:
R102#show ip bgp BGP table version is 6, local router ID is 172.16.16.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 172.16.16.0/24 0.0.0.0 0 32768 i *> 172.31.130.0 0.0.0.0 0 32768 i *> 192.168.50.0 10.10.20.3 0 0 3 i *> 10.200.200.0 10.10.10.1 0 0 1 i
由于192.168.50.0/24位于R102 BGP表中,因此R102不得向R101通告172.16.16.0/24。
R102#show ip bgp neighbors 10.10.10.1 advertised-routes
BGP table version is 6, local router ID is 172.16.16.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 172.31.130.0 0.0.0.0 0 32768 i
*> 192.168.50.0 10.10.20.3 0 0 3 i
!--- Note 172.16.16.0/24 is not advertised to neighbor 10.10.10.1.
R102#show ip bgp 172.16.16.0
BGP routing table entry for 172.16.16.0/24, version 6
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
!--- This is not advertised to R101.
10.10.20.3
Local
0.0.0.0 from 0.0.0.0 (172.16.16.1)
Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best
然后检查 R102 上条件通告的状态:
R102#show ip bgp neighbors 10.10.10.1 BGP neighbor is 10.10.10.1, remote AS 1, external link BGP version 4, remote router ID 10.200.200.1 BGP state = Established, up for 02:27:07 Last read 00:00:07, hold time is 180, keepalive interval is 60 seconds !--- Output suppressed. For address family: IPv4 Unicast BGP table version 6, neighbor version 6 Index 1, Offset 0, Mask 0x2 Condition-map NON-EXIST, Advertise-map ADVERTISE, status: Withdraw 1 accepted prefixes consume 36 bytes Prefix advertised 3, suppressed 0, withdrawn 1 Number of NLRIs in the update sent: max 1, min 0 !--- Output suppressed.
输出显示,条件通告已撤销,且匹配路由映射ADVERTISE的网络未通告给对等体10.10.10.1。
要确认与route-map ADVERTISE匹配的路由未通告给R101,请检查R101上的BGP表:
R101#show ip bgp 172.16.16.0 % Network not in table
此示例显示当 R102 的 BGP 表中不存在网络 192.168.50.0/24 时 BGP 的情况:
192.168.50.0/24 R102 BGP表中不存在
这些步骤包括:
1.关闭R103上的环回接口0,以便R103不再向R102通告192.168.50.0/24。
R103(config)#interface loopback 0 R103(config-if)#shutdown R103(config-if)# 03:29:36: %LINK-5-CHANGED: Interface Loopback0, changed state to administratively down
2.确认R102未学习192.168.50.0/24,并且网络未包含在R102 BGP表中。
R102#show ip bgp BGP table version is 8, local router ID is 172.16.16.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 172.16.16.0/24 0.0.0.0 0 32768 i *> 172.31.130.0 0.0.0.0 0 32768 i *> 10.200.200.0 10.10.10.1 0 0 1 i !--- Note 192.168.50.0/24 is not present.
3.观察条件通告启动所需的时间:
R102#debug ip bgp updates *Mar 1 02:39:18.059: BGP(0): 10.10.20.3 rcv UPDATE about 192.168.50.0/24 -- withdrawn *Mar 1 02:39:18.059: BGP(0): no valid path for 192.168.50.0/24 *Mar 1 02:39:18.079: BGP(0): nettable_walker 192.168.50.0/24 no best path *Mar 1 02:39:18.219: BGP(0): 10.10.10.1 computing updates, afi 0, neighbor version 10, table version 11, starting at 0.0.0.0 *Mar 1 02:39:18.219: BGP(0): 10.10.10.1 send unreachable 192.168.50.0/24 *Mar 1 02:39:18.219: BGP(0): 10.10.10.1 send UPDATE 192.168.50.0/24 -- unreachable *Mar 1 02:39:18.219: BGP(0): 10.10.10.1 1 updates enqueued (average=27, maximum=27) *Mar 1 02:39:18.219: BGP(0): 10.10.10.1 update run completed, afi 0, ran for 0ms, neighbor version 10, start version 11, throttled to 11 *Mar 1 02:40:04.747: BPG(0): Condition NON-EXIST changes to Advertise *Mar 1 02:40:04.747: BGP(0): net 172.16.16.0/24 matches ADV MAP ADVERTISE: bump version to 12 *Mar 1 02:40:05.187: BGP(0): nettable_walker 172.16.16.0/24 route sourced locally *Mar 1 02:40:05.187: BGP(0): 10.10.10.1 computing updates, afi 0, neighbor version 11, table version 12, starting at 0.0.0.0 *Mar 1 02:40:05.187: BGP(0): 10.10.10.1 172.16.16.0/24 matches advertise map ADVERTISE, state: Advertise *Mar 1 02:40:05.187: BGP(0): 10.10.10.1 send UPDATE (format) 172.16.16.0/24, next 10.10.10.2, metric 0, path *Mar 1 02:40:05.187: BGP(0): 10.10.10.1 1 updates enqueued (average=52, maximum=52) *Mar 1 02:40:05.187: BGP(0): 10.10.10.1 update run completed, afi 0, ran for 0ms, neighbor version 11, start version 12, throttled to 12
注意:调试输出可能因使用的软件版本而异。
有条件通告进程由BGP扫描程序进程触发,它每60秒运行。这意味着条件通告生效的最长时间是 60 秒。条件通告可以更快生效,这取决于从 BGP 表中删除跟踪的路由的时间以及 BGP 扫描程序的下个实例出现的时间。
在R102上运行以下命令,以验证R102上邻居10.10.10.1的条件通告状态:
R102#show ip bgp neighbors 10.10.10.1 BGP neighbor is 10.10.10.1, remote AS 1, external link BGP version 4, remote router ID 10.200.200.1 BGP state = Established, up for 02:45:27 Last read 00:00:27, hold time is 180, keepalive interval is 60 seconds !--- Output suppressed. For address family: IPv4 Unicast BGP table version 12, neighbor version 12 Index 1, Offset 0, Mask 0x2 Condition-map NON-EXIST, Advertise-map ADVERTISE, status: Advertise 1 accepted prefixes consume 36 bytes Prefix advertised 6, suppressed 0, withdrawn 4 Number of NLRIs in the update sent: max 1, min 0 !--- Output suppressed.
R101 BGP表和路由表有172.16.16.0/24,如下所示:
注意:在此示例输出中,除 BGP 路由器向其对等体发送的正常 BGP 通告(网络 172.31.130.0/16)以外,还发送了条件 BGP 通告(网络 172.16.16.0/24)。
R101#show ip bgp BGP table version is 18, local router ID is 10.200.200.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 172.16.16.0/24 10.10.10.2 0 0 2 i *> 172.31.130.0 10.10.10.2 0 0 2 i *> 10.200.200.0 0.0.0.0 0 32768 i
R101#show ip route bgp
172.16.0.0/24 is subnetted, 1 subnets
B 172.16.16.0 [20/0] via 10.10.10.2, 00:09:32
B 172.31.130.0/16 [20/0] via 10.10.10.2, 02:48:46
此示例涉及在R102中重新安装192.168.50.0/24网络,以查看BGP如何从Advertise更改为Withdraw。
BGP如何从通告更改为撤消
要重新安装192.168.50.0/24,请运行 no shutdown 命令将R103上的接口loopback 0设置为UP。
R103(config)#interface loopback 0 R103(config-if)#no shutdown R103(config-if)# 03:49:06: %LINK-3-UPDOWN: Interface Loopback0, changed state to up 03:49:07: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up !--- R102 kicks in conditional advertisement the moment the
!--- conditional network is received again. *Mar 1 02:51:42.227: BGP(0): 10.10.20.3 rcvd UPDATE w/ attr: nexthop 10.10.20.3, origin i, metric 0, path 3 *Mar 1 02:51:42.227: BGP(0): 10.10.20.3 rcvd 192.168.50.0/24 *Mar 1 02:51:42.247: BGP(0): Revise route installing 192.168.50.0/24 -> 10.10.20.3 to main IP table *Mar 1 02:51:42.379: BGP(0): 10.10.10.1 computing updates, afi 0, neighbor version 12, table version 13, starting at 0.0.0.0 *Mar 1 02:51:42.379: BGP(0): 10.10.10.1 send UPDATE (format) 192.168.50.0/24, next 10.10.10.2, metric 0, path 3 *Mar 1 02:51:42.379: BGP(0): 10.10.10.1 1 updates enqueued (average=47, maximum=47) *Mar 1 02:51:42.379: BGP(0): 10.10.10.1 update run completed, afi 0, ran for 0ms, neighbor version 12, start version 13, throttled to 13 *Mar 1 02:52:09.159: BPG(0): Condition NON-EXIST changes to Withdraw *Mar 1 02:52:09.159: BGP(0): net 172.16.16.0/24 matches ADV MAP ADVERTISE: bump version to 14 *Mar 1 02:52:09.499: BGP(0): nettable_walker 172.16.16.0/24 route sourced locally *Mar 1 02:52:11.559: BGP(0): 10.10.10.1 computing updates, afi 0, neighbor version 13, table version 14, starting at 0.0.0.0 *Mar 1 02:52:11.559: BGP(0): 10.10.10.1 172.16.16.0/24 matches advertise map ADVERTISE, state: Withdraw *Mar 1 02:52:11.559: BGP(0): 10.10.10.1 send unreachable 172.16.16.0/24 *Mar 1 02:52:11.559: BGP(0): 10.10.10.1 send UPDATE 172.16.16.0/24 -- unreachable *Mar 1 02:52:11.559: BGP(0): 10.10.10.1 1 updates enqueued (average=27, maximum=27) *Mar 1 02:52:11.559: BGP(0): 10.10.10.1 update run completed, afi 0, ran for 0ms, neighbor version 13, start version 14, throttled to 14
R102不再向R101通告172.16.16.0/24。
R102#show ip bgp neighbors 10.10.10.1 advertised-routes BGP table version is 14, local router ID is 172.16.16.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 172.31.130.0 0.0.0.0 0 32768 i *> 192.168.50.0 10.10.20.3 0 0 3 i !--- Note 172.16.16.0/24 is not advertised. R102#show ip bgp neighbors 10.10.10.1 BGP neighbor is 10.10.10.1, remote AS 1, external link BGP version 4, remote router ID 10.200.200.1 BGP state = Established, up for 03:01:32 Last read 00:00:31, hold time is 180, keepalive interval is 60 seconds Neighbor capabilities: !--- Output supressed. For address family: IPv4 Unicast BGP table version 14, neighbor version 14 Index 1, Offset 0, Mask 0x2 Condition-map NON-EXIST, Advertise-map ADVERTISE, status: Withdraw 1 accepted prefixes consume 36 bytes Prefix advertised 7, suppressed 0, withdrawn 5 Number of NLRIs in the update sent: max 1, min 0 !--- Output supressed.
注意:在实际情况中,AS1 和 AS3 将连接到 Internet(全局 BGP)。 因此,网络192.168.50.0/24可以通过全局bgp网状从AS3传播到AS1(R101)BGP表。而 AS1 则可向 R102 传播前缀 192.168.50.0(根据 AS1 和 AS2 之间的策略协议)。 如果R101将从全局BGP网状获知的AS3路由传播到R102,则如果未在不存在映射中放置其他检查,则条件通告可能会失败。
请考虑以下情况,以便更好地了解条件通告的失败原因。AS1 从全局 BGP 网格获知 192.168.50.0/24 并向 AS2 (R102) 通告 192.168.50.0/24。R102也从R103的直接对等体那里获知前缀192.168.50.0/24 (在R102到R103的链路上)。 当R102和R103之间的直接链路发生故障时,您预计前缀192.168.50.0/24不再存在于R102的BGP表中,并且条件通告开始并向R101通告前缀172.16.16.0/24。但是,由于前缀192.168.50.0/24继续存在于R102 BGP表中(从R101获知),条件通告会断开,因为不存在映射中的前缀仍存在于R102 BGP表中。
为了确保前缀192.168.50.0/24仅从与AS3的直接连接(R102到R103)获知以便条件通告生效,请在non-exist map下添加一个match as_path语句,该语句匹配从直接连接获知的前缀192.168.50.0/24的AS_PATH(在本例中为AS 3)。 本例的正则表达式是 ^3。有关正则表达式的详细信息,请参阅在 BGP 中使用正则表达式。请注意,您不能只匹配 as-path 而不匹配前缀。match as-path 只能补充已匹配前缀的匹配标准。换句话说,如果某个 AS # 不存在前缀,则不能向邻居通告一些前缀。
此处显示 R102 上的新配置。新增内容用粗体显示。
| R101 |
|---|
hostname R102 ! interface Loopback0 ip address 172.16.16.1 255.255.255.0 ! interface Serial8/0 ip address 10.10.10.2 255.255.255.0 ! interface Serial9/0 ip address 10.10.20.2 255.255.255.0 ! router bgp 2 bgp log-neighbor-changes network 172.16.16.0 mask 255.255.255.0 network 172.31.130.0 neighbor 10.10.10.1 remote-as 1 neighbor 10.10.10.1 advertise-map ADVERTISE non-exist-map NON-EXIST neighbor 10.10.20.3 remote-as 3 ! ip route 172.31.130.0 255.255.0.0 Null0 ! ip as-path access-list 1 permit ^3 ! access-list 60 permit 172.16.16.0 0.0.0.255 access-list 65 permit 192.168.50.0 0.0.0.255 ! route-map NON-EXIST permit 10 match ip address 65 match as-path 1 ! route-map ADVERTISE permit 10 match ip address 60 ! |
| 版本 | 发布日期 | 备注 |
|---|---|---|
7.0 |
15-Jul-2026
|
重新认证 — 更新格式并按类别添加。 |
6.0 |
25-Nov-2025
|
重新认证、重新格式化并添加了AI Content User Written标签。 |
5.0 |
13-Dec-2024
|
重新认证、重新格式化和精简步骤重组。 |
4.0 |
26-Jun-2023
|
重新认证 |
1.0 |
28-Dec-2001
|
初始版本 |