本文件說明如何設定並驗證邊界閘道通訊協定 (BGP) 條件式通告功能。
思科建議您瞭解以下主題:
本文件所述內容不限於特定軟體和硬體版本。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
邊界閘道協定 (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 資料表中,請勿向 R101 發出 172.16.16.0/24 網路通告。
如果 192.168.50.0/24 不存在 R102 的 BGP 資料表中,則可向 R101 發出 172.16.16.0/24 網路通告。
在Cisco IOS 12.2T或更高版本中,exist-map關鍵字也可用於完成以下任務:
如果 192.168.50.0/24 存在 R102 的 BGP 資料表中,則可向 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 宣告。
為了確認符合路由對應 ADVERTISE 的路由並未向 R101 宣告,請檢查 R101 的 BGP 資料表:
R101#show ip bgp 172.16.16.0 % Network not in table
此範例指出如果網路 192.168.50.0/24 不存在 R102 BGP 資料表中,則 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 如何從「Advertise」變更為「Withdraw」
若要重新安裝192.168.50.0/24,請運 no shutdown 行命令將R103的介面環回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 都連線到網際網路(全域 BGP)。 因此,網路 192.168.50.0/24 可透過 global bgp mesh 從 AS3 傳播到 AS1 (R101) BGP 資料表。相對地,AS1 可將首碼 192.168.50.0 傳播到 R102(視 AS1 和 AS2 之間的原則協議而定)。 如果 R101 將從全域 BGP 網狀網路得知的 AS3 路由傳播給 R102,則在沒有對 non-exist map 執行額外檢查的情況下,條件式通告可能會失敗。
若要進一步釐清條件式通告失敗的原因,請考量以下情境。AS1從全域性bgp網狀網獲取192.168.50.0/24,並向AS2(R102)通告192.168.50.0/24。R102 也從它與 R103 的直接對等連線(透過 R102 與 R103 的連結)得知首碼 192.168.50.0/24。 當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)的直接連線中得知,藉此讓條件式通告得以觸發,在從直接連線(此例為 AS3)得知首碼 192.168.50.0/24 後,請在與首碼的 AS_PATH 相符的 non-exist map 下方加入 match as_path 陳述式。 此例的標準運算式為 ^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內容使用者寫入標籤。 |
5.0 |
13-Dec-2024
|
重新認證、重新格式化和精簡步驟重組。 |
4.0 |
26-Jun-2023
|
重新認證 |
1.0 |
28-Dec-2001
|
初始版本 |