简介
本文档介绍如何使用HSRP在多宿主边界网关协议(BGP)网络中提供冗余。
先决条件
要求
Cisco 建议您了解以下主题:
使用的组件
本文档不限于特定的软件和硬件版本。
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您的网络处于活动状态,请确保您了解所有命令的潜在影响。
规则
有关文档规则的详细信息,请参阅 Cisco 技术提示规则。
背景信息
本文讲述了您在具有两个独立的网络服务提供商(ISP)连接的多址边界网关协议(BGP)网络中如何提供冗余性。 如果与一个 ISP 的连接发生故障,系统将使用 BGP set as-path {tag | prepend as-path-string} 命令和热备份路由器协议 (HSRP)。
本文档中的配置是为了实现以下网络策略:
-
所有源自网络 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 就是为了满足这些要求而设计的。有关详细信息,请参阅了解热备份路由器协议的特性和功能。
第二个目标可通过BGP set as-path prepend命令实现,该命令允许BGP通过R2到ISP-B链路传播更长的AS路径(通过多次预置自己的AS编号的方式),以使用前缀192.168.21.0/24。因此,所有从AS 100外部发往192.168.21.0/24的流量都使用通过ISP-A到R1链路的更短AS路径。如果主路径(从ISP-A到R1)发生故障,所有流量将采用较长的AS路径(从ISP-B到R2)以到达网络192.168.21.0/24。要了解有关BGP set as-path prepend命令的更多信息,请参阅检查边界网关协议案例研究文档中的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
|
验证
本部分所提供的信息可用于确认您的配置是否正常工作。
根据命令输出和特定模式,CLI分析器可以嵌入提供帮助和其他信息的链接和工具提示。
注意:只有注册的思科用户才能访问内部思科工具和信息。
当您在任一网络中配置冗余时,都必须考虑两件事:
-
数据包从本地网络到目标网络的冗余路径的创建。
-
数据包从目标网络回到本地网络的冗余路径的创建。
本地网络到目的地的信息包
在本示例中,本地网络为192.168.21.0/24。路由器R1和R2在连接到接口Ethernet1的以太网段上运行HSRP。R1被配置为HSRP活动路由器,备用优先级为105,R2被配置为100。standby 1 track Serial0(s0)命令允许HSRP进程监控该接口。如果接口状态断开,HSRP 优先级会降低。当接口s0's路由协议断开后,HSRP优先级减少到95 (优先级降低的默认值是10)。 这会提高另一个 HSRP 路由器 R2 的优先级(优先级为 100)。R2成为HSRP活动路由器,吸引发往活动HSRP地址192.168.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#
show standby命令将R1显示为活动HSRP路由器,因为它的优先级较高,为105。由于R1是活动路由器,因此R1拥有备用IP地址192.168.21.10。所有来自配置了默认网关的主机的IP流量都通过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命令。
目的地到本地网络的信息包
根据Background Information部分中定义的网络策略,因为ISP-A是您的主路径,而ISP-B是流向192.168.21.0/24的流量的备用路径(由于向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。
相关信息