本文档介绍使用多个服务提供商(多宿主)运行边界网关协议(BGP)的结果。
Cisco 建议您了解以下主题:
本文档中的信息基于运行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。
如果只想接收来自直连服务提供商的默认路由,请使用Configuration to Receive Default Routes Only。有关本文档配置中使用的正则表达式的详细信息,请参阅在BGP中使用正则表达式。
本部分提供有关如何配置本文档所述功能的信息。
本文档使用以下网络设置:

在此网络图中,AS 300将10.1.0.0/8和10.2.0.0/8通告给外部。
此配置允许路由器A与其他自治系统中的BGP扬声器对等。route-map localonly仅允许将本地生成的路由通告给两个服务提供商。换句话说,它们会过滤从一个服务提供商返回另一个服务提供商的Internet路由。这可以防止您的自治系统成为互联网流量的中转AS的风险。
| Router 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 |
以下自治系统路径访问列表只允许本地生成的 BGP 路由:
ip as-path access-list 10 permit ^$
下面是一个路由映射示例,该路由映射使用自治系统路径访问列表对通告给服务提供商网络中外部邻居的路由进行过滤:
route-map localonly permit 10 match as-path 10
| Router 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
| Router 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
|
初始版本 |