拓扑图如图所示:

 

 

第一步:通过配置HSRP实现PC1去往PC2的流量走上面的路径,PC2去往PC1的流量走下面的路径

配置:PC1

ip:10.1.1.1

掩码:255.0.0.0

网关:10.1.1.100

PC2:

 

ip:20.1.1.1

掩码:255.0.0.0

网关:20.1.1.100

R2:

 

R2(config)#int e0/0

R2(config-if)#ip ad 10.1.1.2 255.0.0.0

R2(config-if)#standby 10 ip 10.1.1.100 设置虚拟网关

R2(config-if)#stan 10 pri 200 配置优先级使其高于默认的100

R2(config-if)#stan 10 pre 配置抢占

R2(config-if)#no sh

R2(config-if)#int e0/1

 

R2(config-if)#ip ad 20.1.1.2 255.0.0.0

R2(config-if)#stan 20 ip 20.1.1.100

R2(config-if)#no sh

R3:

 

R3(config)#int e0/0

R3(config-if)#ip ad 10.1.1.3 255.0.0.0

R3(config-if)#standby 10 ip 10.1.1.100

R3(config-if)#no sh

R3(config-if)#int e0/1

R3(config-if)#ip ad 20.1.1.3 255.0.0.0

R3(config-if)#standby 20 ip 20.1.1.100

R3(config-if)#standby 20 pri 200

R3(config-if)#standby 20 pre

R3(config-if)#no sh

如上配置使PC1去往PC2选择R2 因为R2的e0/0优先级高于R3e0/0 而在HSRP中,优先级越高越优,同理PC2去往PC1选择R3

再看看其状态:

 

 

R2(config-if)#do show stan bri

                     P indicates configured to preempt.

                     |

Interface   Grp Prio P State    Active          Standby         Virtual IP     

Et0/0       10  200  P Active   local           10.1.1.3        10.1.1.100     

Et0/1       20  100    Standby  20.1.1.3        local           20.1.1.100 

 

R3(config)#do show stan bri

                     P indicates configured to preempt.

                     |

Interface   Grp Prio P State    Active          Standby         Virtual IP     

Et0/0       10  100    Standby  10.1.1.2        local           10.1.1.100     

Et0/1       20  200  P Active   local           20.1.1.2        20.1.1.100 

 

 

 

 

接下来验证:

OK实现去走上面回来走下面!

第二步:当down掉active路由器,看能否自动切换,这里down掉R2的e0/0,看路径是否换到下面了,也就是10.1.1.3

 

R2(config)#int e0/0

R2(config-if)#sh

 

 

 

R2(config-if)#do show stan bri

                     P indicates configured to preempt.

                     |

Interface   Grp Prio P State    Active          Standby         Virtual IP     

Et0/0       10  200  P Init     unknown         unknown         10.1.1.100     

Et0/1       20  100    Standby  20.1.1.3        local           20.1.1.100  

 

R3(config-if)#do show stan bri

                     P indicates configured to preempt.

                     |

Interface   Grp Prio P State    Active          Standby         Virtual IP     

Et0/0       10  100    Active   local           unknown         10.1.1.100     

Et0/1       20  200  P Active   local           20.1.1.2        20.1.1.100  

可以看到切换成功!现在重新启动R2e0/0 使其恢复正常

 

第三步:验证对象追踪!

PS:当没有配置这个特性的时候,当PC1有去往PC2的流量,而R2的e0/1又出现问题了,这时候链路并不能自动切换,因为R3是通过接受从R2e0/0发来的hello信息来判断R2是否为正常状态,所以也只能检测R2的e0/0!所以启动对象追踪很重要的!

来看下现象。首先未配置追踪时,down掉R2e0/1接口

 

R2(config-if)#int e0/1

R2(config-if)#sh

 

 

可以看到数据包到e0/1就走不下去了,出问题了!

现在配置追踪特性

R2(config-if)#int e0/0

R2(config-if)#standby 10 track ethernet 0/1 120

配置追踪特性后:

 

发现还是没有自动切换,为什么?我们再检查前面的配置,发现R3的e0/0没有配置抢占特性,所以它不会主动成为active,现在配上这个命令

 

R3(config-if)#standby 10 preempt 

*Mar  1 01:36:54.275: %HSRP-5-STATECHANGE: Ethernet0/0 Grp 10 state Standby -> Active

可以看到提示成为了active,也肯定就切换了链路了!!

这里说下这个命令standby 10 track ethernet 0/1 120

当追踪到e0/1出现问题事,就把standby 10的优先级减少120,原来为200!所以现在的优先级就为80,小于R3e0/0的100!再加上下面也配置了抢占,所以它就成为了active!如果不加120,默认就是减少10!

 

OK,实验完毕!加油!