本文讲述了您在具有两个独立的网络服务提供商(ISP)连接的多址边界网关协议(BGP)网络中如何提供冗余性。 如果与一个 ISP 的连接发生故障,系统将使用 BGP set as-path {tag | prepend as-path-string}命令和热备份路由器协议(HSRP)。
本文档的读者应掌握以下这些主题的相关知识:
本文档不限于特定的软件和硬件版本。
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您使用的是真实网络,请确保您已经了解所有命令的潜在影响。
有关文件规则的更多信息请参见“ Cisco技术提示规则”。
本文档中的配置是为了实现以下网络策略:
所有源自网络 192.168.21.0/24 中的主机,发往 Internet 的出站流量都必须经过 R1 到 ISP-A 链路。但是,如果该链路发生故障或 R1 发生故障,则所有出站流量都必须通过 R2 到 ISP-B 链路重新路由(然后到达 Internet),而无需进行人工干预。
从Internet发往自治系统AS 100的所有入站流量必须通过R1路由。如果从ISP-A到R1的链路发生故障,则入站流量必须自动通过ISP-B重新路由到R2。
这些要求可以通过两种技术来实现:BGP 和 HSRP。
第一个目标,完全冗余出站路径可以通过 HSRP 实现。通常,PC 没有收集和交换路由信息的能力。默认网关的 IP 地址在 PC 上是静态配置的,如果网关路由器出现故障,PC 会失去与其所在的本地网段以外的任何设备的连接。即使存在备用网关也是如此。HSRP 就是为了满足这些要求而设计的。有关详细信息,请参阅 HSRP 的特性和功能。
第二个目标可通过BGP set as-path prepend 命令实现,该命令允许BGP通过R2向ISP-B链路传播更长的AS路径(通过多次预置其自己的AS编号)以获得前缀192.168.21.0/24。因此,所有发往192.168.21.0/24的流量都来自外部AS 100通过ISP-A到R1链路采用较短的AS路径。如果主路径(ISP-A到R1)发生故障,所有流量都采用较长的AS路径(ISP-B到R2)以到达网络192.168.21.0/24。要了解有关BGP set as-path prepend命令的详细信息,请参阅BGP中的AS_PATH属性图案例研究文档。
本部分提供有关如何配置本文档所述功能的信息。
注意:使用命令查找工具(仅限注册客户)可查找有关本文档中使用的命令的详细信息。
本文档使用此处所示的网络设置:
在此图表中,路由器1 (R1)和路由器2 (R2)在AS 100中分别有与ISP-A (AS 300)和ISP-B (AS 400)对应的外部BGP(eBGP)对等连接。路由器 6 (R6) 是 AS 600 的一部分,AS 600 分别有与 ISP-A 和 ISP-B 配对的 eBGP。R1. R2具有iBGP对等,这是确保最佳路由所必需的。例如,当您尝试到达AS 400内部路由时,R1不会使用AS 300上的较长路径。R1将流量转发到R2。
R1 和 R2 还通过一个常用的以太网段针对 HSRP 进行了配置。在同一个以太网段上的主机有一个指向 HSRP 备用 IP 地址 192.168.21.10 的默认路由。
R1 |
---|
Current configuration hostname R1 ! interface serial 0 ip address 192.168.31.1 255.255.255.0 ! interface Ethernet1 ip address 192.168.21.1 255.255.255.0 standby 1 priority 105 standby 1 preempt delay minimum 60 standby 1 ip 192.168.21.10 standby 1 track Serial0 !--- The standby track serial command tracks the state of !--- the Serial0 interface and brings down the !--- priority of standby group 1, if the interface goes down. !--- The standby preempt delay minimum 60 command makes sure that !--- R1 preempts and takes over as active router again. This command also ensures that !--- the router waits 60 seconds before doing so in order to give BGP time enough !--- to converge and populate the routing table. This avoids !--- traffic being sent to R1 before it is ready to forward it. ! ! router bgp 100 no synchronization network 192.168.21.0 neighbor 192.168.21.2 remote-as 100 neighbor 192.168.21.2 next-hop-self neighbor 192.168.31.3 remote-as 300 no auto-summary ! |
R2 |
---|
Current configuration: hostname R2 ! interface serial 0 ip address 192.168.42.2 255.255.255.0 ! interface Ethernet1 ip address 192.168.21.2 255.255.255.0 standby 1 priority 100 standby 1 preempt standby 1 ip 192.168.21.10 ! ! router bgp 100 no synchronization network 192.168.21.0 neighbor 192.168.21.1 remote-as 100 neighbor 192.168.21.1 next-hop-self neighbor 192.168.42.4 remote-as 400 neighbor 192.168.42.4 route-map foo out !--- It appends AS 100 to the BGP updates sent to AS 400 !--- in order to make it a backup for the ISP-A to R1 path. no auto-summary ! access-list 1 permit 192.168.21.0 route-map foo permit 10 match ip address 1 set as-path prepend 100 end |
本部分所提供的信息可用于确认您的配置是否正常工作。
命令输出解释程序工具(仅限注册用户)支持某些 show 命令,使用此工具可以查看对 show 命令输出的分析。
当您在任一网络中配置冗余时,都必须考虑两件事:
数据包从本地网络到目标网络的冗余路径的创建。
数据包从目标网络回到本地网络的冗余路径的创建。
在本例中,本地网络为192.168.21.0/24。路由器R1和R2在连接到以太网接口1的以太网网段上运行HSRP。R1配置为HSRP活动路由器,备用优先级为105,R2配置为备用优先级为100。备用1跟踪Serial0(s0)命令,允许HSRP进程监控该接口。如果接口状态断开,HSRP 优先级会降低。当接口s0's路由协议断开后,HSRP优先级减少到95 (优先级降低的默认值是10)。 这会提高另一个 HSRP 路由器 R2 的优先级(优先级为 100)。R2 将成为 HSRP 活动路由器,并将发往活动 HSRP 地址 192.169.21.10 的流量吸引过来。
当R1上的接口s0处于打开状态时,发出show standby命令以查看活动HSRP路由器:
R1#show standby Ethernet1 - Group 1 Local state is Active, priority 105, may preempt Hellotime 3 sec, holdtime 10 sec Next hello sent in 0.338 Virtual IP address is 192.168.21.10 configured Active router is local Standby router is 192.168.21.2 expires in 8.280 Virtual mac address is 0000.0c07.ac01 13 state changes, last state change 00:46:10 IP redundancy name is "hsrp-Et0-1"(default) Priority tracking 1 interface, 1 up: Interface Decrement State Serial0 10 Up R2#show standby Ethernet1 - Group 1 State is Standby 56 state changes, last state change 00:05:13 Virtual IP address is 192.168.21.10 Active virtual MAC address is 0000.0c07.ac01 Local virtual MAC address is 0000.0c07.ac01 (default) Hello time 3 sec, hold time 10 sec Next hello sent in 1.964 secs Preemption enabled Active router is 192.168.21.1, priority 105 (expires in 9.148 sec) Standby router is local Priority 100 (default 100) IP redundancy name is "hsrp-Et0-1" (default) R1#show standby ethernet 1 brief P indicates configured to preempt. | Interface Grp Prio P State Active addr Standby addr Group addr Et1 1 105 P Active local 192.168.21.2 192.168.21.10 R1# R2#show standby ethernet 1 brief P indicates configured to preempt. | Interface Grp Prio P State Active Standby Virtual IP Et1 1 100 P Standby 192.168.21.1 local 192.168.21.10 R2#
由于优先级为105,因此show standby命令将R1显示为活动HSRP路由器。由于R1是活动路由器,因此R1拥有备用IP地址192.168.21.10。来自配置了默认网关的主机的所有IP流量均为192.168.21.10通过R1的路由。
如果关闭路由器R1的s0接口,则HSRP活动路由器会发生更改,因为R1的HSRP配置了standby track serial 0命令。当Serial 0接口协议关闭时,HSRP将R1的优先级降低10(默认)到95。R1将其状态更改为“备用”。R2接管主用路由器,因此拥有备用IP地址192.168.21.10。因此,从192.168.21.0/24网段中的主机发往的所有流量都通过R2路由流量。 debug 和show 命令输出确认了相同的结果。
R1(config)# interface s0 R1(config-if)# shut %STANDBY-6-STATECHANGE: Standby: 1: Ethernet1 state Active -> Speak %LINK-5-CHANGED: Interface Serial0, changed state to administratively down %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0, changed state to down %STANDBY-6-STATECHANGE: Standby: 1: Ethernet1 state Speak -> Standby %LINK-3-UPDOWN: Interface Serial0, changed state to down: %STANDBY-6-STATECHANGE: Standby: 1: Ethernet1 state Active -> Speak %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0, changed state to down %STANDBY-6-STATECHANGE: Standby: 1: Ethernet1 state Speak -> Standby
请注意,R1 变成了备用路由器。
如果 R2 进入活动状态,则您会看到类似以下的输出:
R2# %STANDBY-6-STATECHANGE: Standby: 1: Ethernet1 state Standby -> Active
如果在R1和R2上执行show standby命令,观察R1上接口s0关闭后的备用优先级:
R1#show standby Ethernet1 - Group 1 Local state is Standby, priority 95 (confgd 105), may preempt Hellotime 3 sec, holdtime 10 sec Next hello sent in 0.808 Virtual IP address is 192.168.21.10 configured Active router is 192.168.21.2, priority 100 expires in 9.008 Standby router is local 15 state changes, last state change 00:00:40 IP redundancy name is "hsrp-Et0-1" (default) Priority tracking 1 interface, 0 up: Interface Decrement State Serial0 10 Down (administratively down) R1# R2#show standby Ethernet1 - Group 1 State is Active 57 state changes, last state change 00:00:33 Virtual IP address is 192.168.21.10 Active virtual MAC address is 0000.0c07.ac01 Local virtual MAC address is 0000.0c07.ac01 (bia) Hello time 3 sec, hold time 10 sec Next hello sent in 2.648 secs Preemption enabled Active router is local Standby router is 192.168.21.1, priority 95 (expires in 7.096 sec) Priority 100 (default 100) IP redundancy name is "hsrp-Et0-1" (default) R2# R2# R1#sh standby ethernet 1 brief P indicates configured to preempt. | Interface Grp Prio P State Active addr Standby addr Group addr Et0 1 95 P Standby 192.168.21.2 local 192.168.21.10 R1# R2#sh standby ethernet 1 brief P indicates configured to preempt. | Interface Grp Prio P State Active Standby Virtual IP Et0 1 100 P Active local 192.168.21.1 192.168.21.10 R2#
注意R1的备用优先级从105减少到95,并且R2成为主路由器。
如果ISP-A和R1之间的连接发生故障,HSRP会降低R1上备用组的优先级。R1从主用状态变为备用状态。R2 从备用状态进入活动状态。备用IP地址192.168.21.10在R2上激活,主机使用R2和ISP-B将数据流发送到互联网,为出局流量提供备选路径。
有关 HSRP standby track 命令的详细信息,请参阅如何使用 standby preempt 和 standby track 命令。
根据背景信息部分中定义的网络策略,因为对发往 192.168.21.0/24 的流量而言,ISP-A 是您的主路径,ISP-B 是备用路径(因为与 ISP-A 的连接的带宽更大等原因),您可以在 R2 宣布给 ISP-B 的 BGP 更新信息中附加自己的 AS 号码,以便使通过 ISP-B 的 AS 路径显得更长。为此,请为BGP邻居192.168.42.4配置路由映射。在该路由映射中,使用set as-path prepend命令附加您自己的AS。将此路由映射应用到针对邻居 192.168.42.4 的出站更新。
注:在生产中,您必须多次附加AS编号,以确保已通告的工艺路线变得不那么首选。
以下是在 R1 到 ISP-A 和 R2 到 ISP-B 之间的 BGP 连接畅通时,R6 中针对网络 192.168.21.0 的 BGP 表:
R6# show ip bgp 192.168.21.0 BGP routing table entry for 192.168.21.0/24, version 30 Paths: (2 available, best #1) Advertised to non peer-group peers: 192.168.64.4 300 100 192.168.63.3 from 192.168.63.3 (10.5.5.5) Origin IGP, localpref 100, valid, external, best, ref 2 400 100 100 192.168.64.4 from 192.168.64.4 (192.168.64.4) Origin IGP, localpref 100, valid, external
因为与来自ISP-B的AS路径{400 100 100}相比较,ISP-A有一个更小的AS路径长度,所以BGP选择了通过ISP-A的AS {300 100}作为最佳路径。从ISP-B有一个更长的AS路径长度的原因是在R2的AS 路径预先考虑配置。
在 R1 和 ISP-A 之间的连接中断后,R6 必须选择备用路径,通过 ISP-B 到达 AS 100 中的网络 192.168.21.0/24:
R1(config)#interface s0 R1(config-if)#shut %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0, changed state to down
以下是 R6 中针对网络 192.168.21.0/24 的 BGP 表:
R6#show ip bgp 192.168.21.0 BGP routing table entry for 192.168.21.0/24, version 31 Paths: (1 available, best #1) Advertised to non peer-group peers: 192.168.63.3 400 100 100 192.168.64.4 from 192.168.64.4 (192.168.64.4) Origin IGP, localpref 100, valid, external, best
有关多宿主网络中的 BGP 配置的详细信息,请参阅两个不同服务提供商(多宿)间的 BGP 的示例配置。
目前没有针对此配置的故障排除信息。