admin管理员组

文章数量:1635850

实验拓扑


先按照拓扑把基本的IP配置好,名字也要改。

R1-gw配置

Router>en
Router#conf t
Router(config)#ho R1-gw
R1-gw(config)#int g0/0
R1-gw(config-if)#ip add 192.168.1.252 255.255.255.0
R1-gw(config-if)#no sh
R1-gw(config-if)#ex

R1-gw(config)#int g0/1
R1-gw(config-if)#ip add 10.1.1.1 255.255.255.0
R1-gw(config-if)#no sh

R1-gw(config)#ip route 0.0.0.0 0.0.0.0  10.1.1.2
R1-gw(config)#int g0/0
R1-gw(config-if)#standby 1 ip 192.168.1.254    #1是组ID,虚拟网关192.168.1.254
R1-gw(config-if)#standby 1 priority 200        #priority优先级
R1-gw(config-if)#standby 1 preempt             #preempt詹先权,这里可以省略,因为R1本来就是活路由跃,但是我个人习惯还是配一下。
R1-gw(config-if)#standby 1 track g0/1          #跟踪外网接口,只可惜这个模拟器不支持后面自定义值,标准写法应该是可以自定值standby 1 track g0/1 50 
R1-gw(config-if)#ex
R1-gw(config)#ex
R1-gw#
R1-gw#show standby brief     #查看热备状况
                     P indicates configured to preempt.
                     |
接口       组ID  优先级 詹先权 状态 活跃状态         备份             虚拟IP
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Gig0/0      1    200 P Active   local           192.168.1.253   192.168.1.254  
                                本地活跃
R1-gw#

说明:standby 1 track g0/1 跟踪外网接口这一项其实是可以直接自定义值的,只可惜这个模拟器不支持后面自定义值,自定义值写法应该是这样:standby 1 track g0/1 50,50就是我们自定义的值,意思就是发现外网断开之后优先级自动降值50。我们等下端口活跃路由看一下它默认是将多少。

R2-gw配置

Router>en
Router#conf t
Router(config)#ho R2-gw

R2-gw(config)#int g0/0
R2-gw(config-if)#ip add 192.168.1.253 255.255.255.0
R2-gw(config-if)#no sh

R2-gw(config)#int g0/1
R2-gw(config-if)#ip add 20.1.1.1 255.255.255.0
R2-gw(config-if)#no sh

R2-gw(config-if)#
R2-gw(config-if)#
R2-gw(config-if)#ho R2-gw
R2-gw(config)#
R2-gw(config)#


R2-gw(config)#ip route 0.0.0.0 0.0.0.0 20.1.1.2
R2-gw(config)#

R2-gw(config)#int g0/0
R2-gw(config-if)#standby 1 ip 192.168.1.254
R2-gw(config-if)#standby 1 priority  
R2-gw(config-if)#standby 1 priority 190     #priority优先级
R2-gw(config-if)#standby 1 preempt          #詹先权,备份路由器一定要配这个`不可省略`
R2-gw(config-if)#
                                            #备份路由器不需要配置跟踪,但是如果还有其他路由器就必须配

R2-gw#show standby brief   #
                     P indicates configured to preempt.(P是詹先权)
                     |
接口       组ID  优先级 詹先权 状态 活跃状态         备份             虚拟IP
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Gig0/0      1    190 P Standby  192.168.1.252   local           192.168.1.254  
                                1.252活跃       本地是备份
R2-gw#

R3配置

Router>en
Router#conf t
Router(config)#ho R3
R3(config)#int g0/0
R3(config-if)#ip add 10.1.1.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#ex

R3(config)#int g0/1
R3(config-if)#ip add 20.1.1.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#ex
R3(config)#
R3(config)#int g0/2
R3(config-if)#ip add 30.1.1.254 255.255.255.0
R3(config-if)#no sh

R3(config)#ip route 0.0.0.0 0.0.0.0 20.1.1.1    #为了实验成功,让他作为回执路由,不然等会我们断开R1的g0/0,备份路由器就算接管,也没有回执路由还是ping不通的,我们就看不到效果。
R3(config)#

说明:为了实验成功,我们在R3上面配置默认路由下一条为20.1.1.1。让他作为PC1pingPC3的回执路由,不然等会我们断开R1的g0/0,备份路由器就算接管,也没有回执路由还是ping不通的,我们就看不到效果。其实只要我们后面学习了nat,就不需要这样了。

验证连通性

分别用PC1、PC2来ping PC3

PC1>PC3

C:\>ping 30.1.1.1

Pinging 30.1.1.1 with 32 bytes of data:

Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126

Ping statistics for 30.1.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

PC2>PC3
C:\>ping 30.1.1.1

Pinging 30.1.1.1 with 32 bytes of data:

Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126

Ping statistics for 30.1.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

验证R1-gw死了的状况

这里我们断开R1-gw的g0/1,通过查看热备状况来看实验效果。

R1-gw(config)#int g0/0
R1-gw(config-if)#sh
R1-gw(config-if)#shutdown 

R1-gw(config-if)#
 %HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Active -> Init

%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to administratively down

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to down

上面我们已经断开了活跃路由器,我们再次用PC1 ping PC3

C:\>ping 30.1.1.1

Pinging 30.1.1.1 with 32 bytes of data:

Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time=1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126

Ping statistics for 30.1.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

C:\>

还是通的,说明备份路由器R2已经接管了。只是在切换的时候有2-3秒不通的情况。但是据我所知在真机中是不会的,因为它有各种机制使得切换速度很快。类似于机房双电源切换一样,切换服务器不关机,速度太快服务器都没有反应过来。

我们来查看一下R2

%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Standby -> Active  #状态存备份变为活跃


R2-gw>en
R2-gw#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R2-gw(config)#show stan
R2-gw(config)#do show stan b
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Gig0/0      1    190 P Active   local           unknown         192.168.1.254
                                                活跃路由死了

验证R1-gw自降优先级的状况

断开R1的g0/1接口

R1-gw(config)#int g0/1
R1-gw(config-if)#shutdown 

R1-gw(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to administratively down

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to down

C:\>ping 30.1.1.1

Pinging 30.1.1.1 with 32 bytes of data:

Request timed out.
Reply from 192.168.1.252: Destination host unreachable.
Reply from 192.168.1.252: Destination host unreachable.
Request timed out.

Ping statistics for 30.1.1.1:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

无法ping通,说明备份路由器R2没有抢过来。

再次查看一下R2

R2-gw(config)#
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Speak -> Standby

R2-gw(config)#
R2-gw(config)#do show stan b
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Gig0/0      1    190 P Standby  192.168.1.252   local           192.168.1.254 

再来查看R1

R1-gw(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to administratively down

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to down

R1-gw(config-if)#
R1-gw(config-if)#
R1-gw(config-if)#do show stan b
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Gig0/0      1    190 P Active   local           192.168.1.253   192.168.1.254  
R1-gw(config-if)#
R1-gw#

确实是没抢过来,说明R1的优先级还是高于R2的190,同时说明活跃路由器R1自降的值不够小于或等于10。那我们如果看到它到底降了多少呢?

R1-gw#show standby 
GigabitEthernet0/0 - Group 1
  State is Active   #当前是活跃状态
    15 state changes, last state change 01:56:56
  Virtual IP address is 192.168.1.254
  Active virtual MAC address is 0000.0C07.AC01
    Local virtual MAC address is 0000.0C07.AC01 (v1 default)
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 2.052 secs
  Preemption enabled
  Active router is local
  Standby router is 192.168.1.253, priority 190 (expires in 7 sec)  #备份路由器信息
  Priority 190 (configured 200) #本地优先级原为200,现在降为190
    Track interface GigabitEthernet0/1 state Down decrement 10  #跟踪到g0/1接口状态为Down,自降值10
  Group name is hsrp-Gig0/0-1 (default)
R1-gw#

现在的状况就是R1和R2都是190,这就尴尬了!那怎么办呢?有两种方法:

  • 把R1优先级从原来的200手动更改为195;
  • 把R2优先级从原来的190手动更改为195;

这里我们选择前者:

R1-gw(config)#int g0/0
R1-gw(config-if)#standby 1 priority 195
R1-gw(config-if)#end
R1-gw#
%SYS-5-CONFIG_I: Configured from console by console

R1-gw#s
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Speak -> Standby

R1-gw#sh stan
R1-gw#sh standby 
GigabitEthernet0/0 - Group 1
  State is Standby   #本地备份
    19 state changes, last state change 02:17:35
  Virtual IP address is 192.168.1.254
  Active virtual MAC address is 0000.0C07.AC01
    Local virtual MAC address is 0000.0C07.AC01 (v1 default)
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 0.983 secs
  Preemption enabled
  Active router is 192.168.1.253, priority 190 (expires in 7 sec)
    MAC address is 0000.0C07.AC01
  Standby router is local
  Priority 185 (configured 195)  #原为195现在降值10,变为185
    Track interface GigabitEthernet0/1 state Down decrement 10
  Group name is hsrp-Gig0/0-1 (default)
R1-gw#

R2接管成功。我们再次用PC1 ping PC3

C:\>ping 30.1.1.1

Pinging 30.1.1.1 with 32 bytes of data:

Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time=1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126

Ping statistics for 30.1.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

C:\>

本文标签: 路由器思科备份协议HSRP