IP : 热备份路由协议 (HSRP)

如何使用 standby preempt 和 standby track 命令

2016 年 10 月 27 日 - 机器翻译
其他版本: PDFpdf | 英语 (2015 年 8 月 22 日) | 反馈


目录


简介

本文档介绍 standby preempt 和 standby track 命令的协同作用,以及您必须在何时使用每一个命令。

standby preempt 命令可赋予热备用路由器协议 (HSRP) 路由器最高优先级,使其立即成为活动路由器。优先级的确定首先取决于所配置的优先级值,然后取决于 IP 地址。在每种情形下,都是更高的值具有更高的优先级。当一个更高优先级的路由器优先于一个较低优先级的路由器时,该路由器会发送一条 Coup 消息。当优先级较低的活动路由器从一个更高优先级的活动路由器接收到 Coup 消息或 Hello 消息时,该路由器会更改为对话状态,并发送放弃消息。

standby track 命令允许您在路由器上为 HSRP 进程指定另一个要监控的接口,以便更改指定组的 HSRP 优先级。如果指定接口的线路协议关闭,则会降低 HSRP 优先级。这意味着如果具有更高优先级的另一个 HSRP 路由器已启用 standby preempt,则该路由器可能会成为活动路由器。

先决条件

要求

本文档没有任何特定的要求。

使用的组件

本文档中的信息基于以下软件和硬件版本:

  • Cisco IOS�软件版本12.2(10b)

  • Cisco 2503 路由器

本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您使用的是真实网络,请确保您已经了解所有命令的潜在影响。

规则

有关文档规则的详细信息,请参阅 Cisco 技术提示规则

背景信息

此图表显示一个将 standby preempt 命令与 standby track 命令一起使用的示例。

6a.gif

配置示例

网络图中,HSRP 是以这种方式配置的:

  • R1 是活动路由器,跟踪 R1 serial 0 接口状态。当 R1 为活动路由器时,从主机(主机 1、2、3)到服务器的所有流量都将通过 R1 路由。

  • R2 是备用路由器,跟踪 R2 serial 1 接口状态。

  • 如果 R1 serial 0 接口断开,则 R1 HSRP 优先级将降低 10。此时,R2 HSRP 优先级高于 R1,并且 R2 将成为活动路由器。当 R2 成为活动路由器后,所有从主机到服务器的流量都将通过 R2 路由。

注意: 使用 HSRP 虚拟 IP 地址(在本例中为 171.16.6.100)配置主机 1、2 和 3 的默认网关。在路由器上配置一个路由协议(例如 RIP),可实现主机和服务器之间的连接。

以下是每个路由器的配置:

路由器 1 (Cisco 2503)
interface Ethernet0 
ip address 171.16.6.5 255.255.255.0

!--- Assigns an IP address to the interface.

no ip redirects 
standby 1 ip 171.16.6.100

!--- Assigns a standby group and standby IP address

standby 1 priority 105

!--- Assign a priority (105 in this case) to the router interface (e0)
!--- for a particular group number (1). The default is 100.

standby 1 preempt

!--- Allows the router to become the active router when the priority 
!--- is higher than all other HSRP-configured routers in the hot standby group. 
!--- If you do not use the standby preempt command in the configuration 
!--- for a router, that router does not become the active router, even if 
!--- the priority is higher than all other routers. 

standby 1 track Serial0

!--- Indicates that HSRP tracks Serial0 interface. 
!--- The interface priority can also be configured, which indicates the 
!--- amount by which the router priority decreases when 
!--- the interface goes down. The default is 10.

interface Serial0 
ip address 171.16.2.5 255.255.255.0

路由器 2 (Cisco 2503)
interface Ethernet0
ip address 171.16.6.6 255.255.255.0

!--- Assigns an IP address to the interface.

no ip redirects
standby 1 ip

!--- Indicates the hot standby group. Here the IP address of the virtual router 
!--- is not configured. See the note after this table.

standby 1 preempt

!--- Allows the router to become the active router when the priority 
!--- is higher than all other HSRP-configured routers in the hot standby group. 
!--- If you do not use the standby preempt command in the configuration 
!--- for a router, that router does not become the active router, even if 
!--- the priority is higher than all other routers. 

standby 1 track Serial1

!--- Indicates that HSRP tracks Serial1 interface. 
!--- The interface priority can also be configured, which indicates the 
!--- amount by which the router priority decreases when 
!--- the interface goes down. The default is 10.
!--- The priority is also not configured and hence the default 
!--- priority value of 100 is applied.

interface Serial1
ip address 171.16.7.6 255.255.255.0

注意: R2 没有配置备用的 IP 地址。这样做是特意为了显示出这是有效配置。当 R1 和 R2 交换 HSRP hello 时,R2 从 R1 获知备用 IP 地址。使用备用 IP 地址配置 R2(在 R1 上配置同样的备用地址)也是有效配置。

R1# show standby
Ethernet0 - Group 1
Local state is Active, priority 105, may preempt
Hellotime 3 sec, holdtime 10 sec
Next hello sent in 1.458
Virtual IP address is 171.16.6.100 configured
Active router is local
Standby router is 171.16.6.6 expires in 8.428
Virtual mac address is 0000.0c07.ac01
2 state changes, last state change 02:09:49
IP redundancy name is "hsrp-Et0-1" (default)
Priority tracking 1 interface, 1 up:
Interface    Decrement  State
Serial0         10      Up
 
R2# show standby
Ethernet0 - Group 1
Local state is Standby, priority 100, may preempt
Hellotime 3 sec, holdtime 10 sec
Next hello sent in 1.814
Virtual IP address is 171.16.6.100
Active router is 171.16.6.5, priority 105 expires in 9.896
Standby router is local
3 state changes, last state change 00:10:21
IP redundancy name is "hsrp-Et0-1" (default)
Priority tracking 1 interface, 1 up:
Interface   Decrement  State
Serial1        10      Up

虽然 R2 没有配置 HSRP 优先级,但是输出显示 R2 优先级为 HSRP 默认值,即 100。两个路由器的输出均表明它们在跟踪 serial 0 的状态。R1 的状态是活动的,而 R2 的状态为备用。最后,两个路由器均使用 standby preempt 命令配置。

如果 R1 的 serial 0 接口断开,将会如何?show standby 命令的输出如下所示:

R1# show standby
Ethernet0 - Group 1
Local state is Standby, priority 95 (confgd 105), may preempt
Hellotime 3 sec, holdtime 10 sec
Next hello sent in 2.670
Virtual IP address is 171.16.6.100 configured
Active router is 171.16.6.6, priority 100 expires in 8.596
Standby router is local
4 state changes, last state change 00:01:45
IP redundancy name is "hsrp-Et0-1" (default)
Priority tracking 1 interface, 0 up:
Interface    Decrement  State
Serial0         10      Down
   
R2# show standby
Ethernet0 - Group 1
Local state is Active, priority 100, may preempt
Hellotime 3 sec, holdtime 10 sec
Next hello sent in 0.810
Virtual IP address is 171.16.6.100
Active router is local
Standby router is 171.16.6.5 expires in 9.028
Virtual mac address is 0000.0c07.ac01
4 state changes, last state change 00:01:38
IP redundancy name is "hsrp-Et0-1" (default)
Priority tracking 1 interface, 1 up:
Interface   Decrement  State
Serial1        10      Up

请注意,在输出中,R1 的 HSRP 优先级降低了 10,变为 95。此更改使 R2 的优先级(其值为 100)高于 R1。因为当 R2 优先级变得更高时为 R2 配置了 standby preempt,则 R2 成为活动路由器,R1 成为备用路由器。此时,如果 R1 serial 0 接口恢复,则 R1 优先级会重新变为 105。在这种情况下,R1 会抢占优先并再次成为 HSRP 活动路由器。

注意: 如果在 R2 上没有配置 standby preempt,则 R2 不会将一条 Coup 消息发送到 R1,而这条消息可导致 R2 变为活动状态。这样的话,R1 将仍为活动路由器。

例如,请看以下配置:

standby priority 120
standby track serial 0
standby track serial 1

HSRP 的优先级 120 配置有 standby priority 命令,并且将 HSRP 配置为跟踪两个接口(Serial 0 和 Serial 1)的状态。由于 standby track 命令中指定递减值,则当所跟踪的接口断开时,HSRP 优先级以默认值 10 递减。最初,两个接口均启用,并且接口的 HSRP 优先级为 120,正如 show standby 命令输出中所示:

R1# show standby
Ethernet0 - Group 1
  Local state is Active, priority 120, may preempt
  Hellotime 3 sec, holdtime 10 sec
  Next hello sent in 1.034
  Virtual IP address is 10.0.0.5 configured
  Active router is local
  Standby router is unknown
  Virtual mac address is 0000.0c07.ac01
  2 state changes, last state change 00:00:04
  IP redundancy name is "hsrp-Et0-1" (default)
  Priority tracking 2 interfaces, 2 up:
    Interface                  Decrement  State
    Serial0                       10      Up
    Serial1                       10      Up
R1#

此时,接口 Serial 0 断开。

R1#
1w0d: %LINK-3-UPDOWN: Interface Serial0, changed state to down
1w0d: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0, changed state to down
R1#

这样会将 HSRP 优先级降低 10,从 120 变为值 110。可以使用 show standby 命令来验证:

R1# show standby
Ethernet0 - Group 1
  Local state is Active, priority 110 (confgd 120), may preempt
  Hellotime 3 sec, holdtime 10 sec
  Next hello sent in 2.544
  Virtual IP address is 10.0.0.5 configured
  Active router is local
  Standby router is unknown
  Virtual mac address is 0000.0c07.ac01
  2 state changes, last state change 00:00:48
  IP redundancy name is "hsrp-Et0-1" (default)
  Priority tracking 2 interfaces, 1 up:
    Interface                  Decrement  State
    Serial0                       10      Down  (line protocol down)
    Serial1                       10      Up
R1#

接下来,第二个所跟踪的接口 Serial 1 断开:

R1#
1w0d: %LINK-3-UPDOWN: Interface Serial1, changed state to down
1w0d: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1, changed state to down
R1#

这样会再次将 HSRP 优先级降低 10,从 110 变为值 100。可以使用 show standby 命令来验证:

R1# show standby
Ethernet0 - Group 1
  Local state is Active, priority 100 (confgd 120), may preempt
  Hellotime 3 sec, holdtime 10 sec
  Next hello sent in 1.846
  Virtual IP address is 10.0.0.5 configured
  Active router is local
  Standby router is unknown
  Virtual mac address is 0000.0c07.ac01
  2 state changes, last state change 00:01:06
  IP redundancy name is "hsrp-Et0-1" (default)
  Priority tracking 2 interfaces, 0 up:
    Interface                  Decrement  State
    Serial0                       10      Down  (line protocol down)
    Serial1                       10      Down  (line protocol down)
R1#

当任何一个所跟踪的串行接口(serial 0 或 serial 1)断开时,均导致优先级变为 110。当这两个所跟踪的串行接口(serial 0 和 serial 1)都断开时,导致优先级变为 100。

注意: 在某些早期版本的 Cisco IOS 中,如果未在 standby track 命令中明确定义递减值,则 HSRP 优先级的递减值不会累加。有关详细信息,请参阅 Bug ID CSCdp72834仅限注册用户)。


相关信息


Document ID: 13780