本檔案將說明透過多個服務提供商(多宿主)執行邊界閘道通訊協定(BGP)的結果。
思科建議您瞭解以下主題:
本檔案中的資訊是根據執行Cisco IOS®軟體版本15.7(3)M8的Cisco 2900系列路由器。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
本檔案介紹邊界閘道通訊協定(BGP),這是用於實現Internet連線備援的關鍵通訊協定之一。將您的網路連線到兩個不同的Internet服務提供商(ISP)時,它稱為多宿主。多宿主提供冗餘和網路最佳化。它會選擇提供到達資源的最佳路徑的ISP。當您使用多個服務提供商運行BGP時,您的自治系統(AS)可能會成為傳輸AS。這會導致網際網路流量通過您的AS,並可能消耗路由器CPU上的所有頻寬和資源。本文檔通過適當的配置示例解決此問題。
如果要接收完整的Internet路由表,請在本地路由器(本文檔示例中的路由器A)上使用Configuration to Receive Full Internet Routing 表。
如果您希望接收直接連線到服務提供商的路由,但使用到網際網路其餘部分的預設路由,請嘗試Configuration to Receive Directly-Connected Routes。
如果您希望僅從直連的服務提供商接收預設路由,請使用配置僅接收預設路由。有關本文檔配置中使用的正規表示式的詳細資訊,請參閱在BGP中使用正規表示式。
本節提供用於設定本文件中所述功能的資訊。
此文件使用以下網路設定:

在此網路圖中,AS 300會將10.1.0.0/8和10.2.0.0/8通告給外部。
此配置允許路由器A與其他自治系統中的BGP揚聲器對等。route-map localonly只允許將本地生成的路由通告給兩個服務提供商。換句話說,它們過濾從一個服務提供商傳回另一個服務提供商的Internet路由。這可以防止您的自治系統成為網際網路流量的中轉AS的風險。
| 路由器 A |
|---|
Current configuration: router bgp 300 network 10.1.0.0 network 10.2.0.0 neighbor 10.10.10.10 remote-as 100 neighbor 10.10.10.10 route-map localonly out !--- Outgoing policy route-map that filters routes to service provider A (SP-A). neighbor 10.20.20.20 remote-as 200 neighbor 10.20.20.20 route-map localonly out !--- Outgoing policy route-map that filters routes to service provider B (SP-B). end |
此AS-Path訪問清單僅允許本地發出的BGP路由:
ip as-path access-list 10 permit ^$
以下是使用該AS-Path訪問清單過濾向服務提供商網路中的外部鄰居通告的路由的路由對映示例:
route-map localonly permit 10 match as-path 10
| 路由器 A |
|---|
Current configuration: router bgp 300 network 10.1.0.0 network 10.2.0.0 neighbor 10.10.10.10 remote-as 100 neighbor 10.10.10.10 route-map localonly out !--- Outgoing policy route-map that filters routes to SP-A. neighbor 10.10.10.10 route-map as100only in !--- Incoming policy route-map that filters routes from SP-A. neighbor 10.20.20.20 remote-as 200 neighbor 10.20.20.20 route-map localonly out !--- Outgoing policy route-map that filters routes to SP-B. neighbor 10.20.20.20 route-map as200only in !--- Incoming policy route-map that filters routes from SP-B. end |
由於您只接受直接連線到服務提供者的路由,因此請過濾它們傳送給您的路由以及您通告的路由。此訪問清單和路由對映僅允許本地發起的路由;使用它來過濾出站路由更新:
ip as-path access-list 10 permit ^$ !--- If you configure the as-path access-list 10 as !--- IP as-path access-list 10 permit ^$, means that the router !--- only sends the prefixes which are generated locally in !--- AS 300 and not from any other AS. route-map localonly permit 10 match as-path 10
此存取清單和路由對映會過濾掉來源不是第一個服務提供者網路的專案;使用它來過濾從服務提供商A(SP-A)獲知的路由:
ip as-path access-list 20 permit ^100$ route-map as100only permit 10 match as-path 20
此存取清單和路由對映會過濾掉來源不在第二個服務提供者網路中的專案;使用它來過濾從服務提供商B(SP-B)獲知的路由:
ip as-path access-list 30 permit ^200$ route-map as200only permit 10 match as-path 30
您還需要兩條分佈回網路其餘部分的預設路由,一條指向每個服務提供商入口點:
ip route 0.0.0.0 0.0.0.0 10.10.10.10 ip route 0.0.0.0 0.0.0.0 10.20.20.20
| 路由器 A |
|---|
Current configuration: router bgp 300 network 10.1.0.0 network 10.2.0.0 neighbor 10.10.10.10 remote-as 100 neighbor 10.10.10.10 route-map localonly out !--- Outgoing policy route-map that filters routes to SP-A. neighbor 10.10.10.10 prefix-list ABC in neighbor 10.20.20.20 remote-as 200 neighbor 10.20.20.20 route-map localonly out !--- Outgoing policy route-map that filters routes to SP-B. neighbor 10.20.20.20 prefix-list ABC in ip prefix-list ABC seq 5 permit 0.0.0.0/0 !--- Prefix list to allow only default route updates. end |
由於您希望路由器A只接收預設路由,而不接收來自SP-A和SP-B的其他網路,因此僅允許預設路由並拒絕所有其他BGP更新。使用此字首清單僅允許預設路由更新0.0.0.0/0,並拒絕路由器A上的所有其他BGP更新:
ip prefix-list ABC seq 5 permit 0.0.0.0/0
透過以下方式將該首碼清單套用到個別BGP鄰居的傳入更新上:
neighbor 10.10.10.10 prefix-list ABC in neighbor 10.20.20.20 prefix-list ABC in
目前尚無適用於此組態的具體疑難排解資訊。
| 修訂 | 發佈日期 | 意見 |
|---|---|---|
3.0 |
22-Jun-2026
|
已更新拼寫、語法、間距和句子結構。 |
2.0 |
07-May-2025
|
已更新格式,以符合思科准則。 |
1.0 |
13-Jul-2022
|
初始版本 |