HSRP相关知识+模拟实验

HSRP:热备份路由器协议(Hot Standby Router Protocol),是cisco的私有协议。

该协议中含有多台路由器,对应一个HSRP组。该组中只有一个路由器承担转发用户流量的职责,这就是活动路由器。当活动路由器失效后,备份路由器将承担该职责,成为新的活动路由器。这就是热备份的原理。

实现HSRP的条件是系统中有多台路由器,它们组成一个“热备份组”,这个组形成一个虚拟路由器。在任一时刻,一个组内只有一个路由器是活动的,并由它来转发数据包,如果活动路由器发生了故障,将选择一个备份路由器来替代活动路由器,但是在本网络内的主机看来,虚拟路由器没有改变。所以主机仍然保持连接,没有受到故障的影响,这样就较好地解决了路由器切换的问题。

为了减少网络的数据流量,在设置完活动路由器和备份路由器之后,只有活动路由器和备份路由器定时发送HSRP报文。如果活动路由器失效,备份路由器将接管成为活动路由器。如果备份路由器失效或者变成了活跃路由器,将由另外的路由器被选为备份路由器。

版本
IOS中的默认HSRP版本是HSRPv1,它允许配置最多255个组号码。由于一台设备可以支持4095个VLAN,因此如果需要的话,管理员要在多个接口上重复使用相同的HSRP组号码。尽管这会引起管理员的困惑,但这种配置方法是可行的。HSRPv1使用虚拟MAC地址是0000.0C07.ACXX,XX表示HSRP组;并向组播地址224.0.0.2发送Hello数据包。

HSRPv2使用的数据包格式与HSRPv1不同。管理员要确保在同一HSRP组中的所有路由器上配置了相同的HSRP版本,因为不同版本的设备之间无法识别Hello消息。HSRPv2的组播地址为224.0.0.102,备份组编号为0-4095。

HSRPv1与v2不兼容,一个HSRP组中主设备与备份设备的版本和编号必须一致。

SLA

Internetwork Performance Monitor (IPM) is a network management application that allows you to monitor the performance of multi-protocol networks. IPM monitors the network performance by configuring collectors on IP SLA (IP Service Level Agreement) capable source devices (routers) and collects the performance-related statistics from these devices(IPM通过收集SLA的数据)

SLA总体实现网络环境稳定性的监测、让网络安装自己的意图来运行
SLA可以测量UDP响应时间、单向延迟、抖动、掉包状况和连通性
可以结合命令行和snmp来实现前期告警 实现触发的trap.

传统的负载均衡、冗余链路的执行是基于链路的中断来完成切换、类似于HSRP的track功能。

很多时候端口的中断、并不一定能反映网络的真实状况。很有可能HSRP追踪到接口是正常的、但是数据不通。SLA可用于链路故障检测。


实验模拟
在这里插入图片描述
SW-1

//封装接口
SW-1(config)#vlan 50
SW-1(config-vlan)#vlan 60
SW-1(config-vlan)#exit
SW-1(config)#interface range g0/0-2
SW-1(config-if-range)#switchport trunk encapsulation dot1q 
SW-1(config-if-range)#switchport mode trunk 
SW-1(config-if-range)#exit
//修改模式为Rapid-PVST(思科私有)
SW-1(config)#spanning-tree mode pvst 
//修改vlan的优先级
SW-1(config)#spanning-tree vlan 50 priority 0
SW-1(config)#spanning-tree vlan 60 priority 4096

SW-1(config)#interface vlan 50
SW-1(config-if)#ip address 192.168.50.1 255.255.255.0
SW-1(config-if)#no shutdown 
SW-1(config-if)#exit
SW-1(config)#interface vlan 60
SW-1(config-if)#ip address 192.168.60.1 255.255.255.0
SW-1(config-if)#no shutdown 
SW-1(config-if)#exit
//将vlan备份到网关
SW-1(config)#interface vlan 50
SW-1(config-if)#standby version 2//版本
SW-1(config-if)#standby 50 ip 192.168.50.254
SW-1(config-if)#standby 50 priority 105//设置优先级,越大越优。默认值为100
SW-1(config-if)#standby 50 preempt delay minimum 60//开启抢占并设置延迟时间.只有主设备开启延迟时间,备用设备不开启。只要主设备出现故障,备份设备立即抢占,以减小对网络的影响
SW-1(config-if)#standby 50 timers 1 3//设置hello包持有时间,全组中尽量一致
SW-1(config-if)#exit
/*SW-1#show standby brief查看备份设置,也可以使用如下命令*/
SW-1(config)#do show run interface vlan 50
Building configuration...

Current configuration : 197 bytes
!
interface Vlan50
 ip address 192.168.50.1 255.255.255.0
 standby version 2
 standby 50 ip 192.168.50.254
 standby 50 timers 1 3
 standby 50 priority 105
 standby 50 preempt delay minimum 60
end

SW-1(config)#do show run interface vlan 60
Building configuration...

Current configuration : 155 bytes
!
interface Vlan60
 ip address 192.168.60.1 255.255.255.0
 standby version 2
 standby 60 ip 192.168.60.254
 standby 60 timers 1 3
 standby 60 preempt
end

SW-1(config)#do show standby brief 
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State   Active          Standby         Virtual IP
Vl50        50   105 P Active  local           192.168.50.2    192.168.50.254
Vl60        60   100 P Standby 192.168.60.2    local           192.168.60.254
//创建地址池
SW-1(config)#ip dhcp pool vlan50
SW-1(dhcp-config)#network 192.168.50.0 /24
SW-1(dhcp-config)#default-router 192.168.50.254
SW-1(dhcp-config)#dns-server 114.114.114.114
SW-1(dhcp-config)#exit 
SW-1(config)#ip dhcp excluded-address 192.168.50.1
SW-1(config)#ip dhcp excluded-address 192.168.60.1
SW-1(config)#ip dhcp excluded-address 192.168.50.254
SW-1(config)#ip dhcp excluded-address 192.168.60.254
SW-1(config)#ip dhcp excluded-address 192.168.50.2
SW-1(config)#ip dhcp excluded-address 192.168.60.2

SW-1(config)#do show run | section dhcp//检查配置
ip dhcp excluded-address 192.168.50.1
ip dhcp excluded-address 192.168.60.1
ip dhcp excluded-address 192.168.50.254
ip dhcp excluded-address 192.168.60.254
ip dhcp excluded-address 192.168.50.2
ip dhcp excluded-address 192.168.60.2
ip dhcp pool vlan50
 network 192.168.50.0 255.255.255.0
 default-router 192.168.50.254 
 dns-server 114.114.114.114 
ip dhcp pool vlan60
 network 192.168.60.0 255.255.255.0
 dns-server 114.114.114.114 
SW-1(config)#vlan 10
SW-1(config-vlan)#exit
SW-1(config)#interface g0/3
SW-1(config-if)#switchport mode access 
SW-1(config-if)#switchport access vlan 10
SW-1(config-if)#exit
SW-1(config)#interface vlan 10
SW-1(config-if)#ip address 17.1.1.1 255.255.255.0
SW-1(config-if)#no shutdown 
SW-1(config-if)#exit
SW-1(config)#ip route 0.0.0.0 0.0.0.0 17.1.1.2
//定义SLA列表
SW-1(config)#ip sla 1
SW-1(config-ip-sla)#icmp-echo 9.9.9.9 source-interface vlan 50//根据源与目的地检测链路状态
SW-1(config-ip-sla-echo)#frequency 5//设置发送ping包的时间间隔
SW-1(config-ip-sla-echo)#timeout 5000//设置时间,在此时间内未收到回复则认为链路故障
SW-1(config-ip-sla-echo)#exit
SW-1(config)#ip sla schedule 1 start-time now life forever //设置ping包的发送时间及持续时间
SW-1(config)#track 50 ip sla 1 reachability//创建track测试链路可达性
SW-1(config-track)#exit
SW-1(config)#interface vlan 50
SW-1(config-if)#standby 50 track 50 decrement 10//若出现故障则优先级减掉设置的数值(本文设置为10)
SW-1(config-if)#exit

SW-2

//封装接口
SW-2(config)#vlan 50
SW-2(config-vlan)#vlan 60
SW-2(config-vlan)#exit
SW-2(config)#interface range g0/0-2
SW-2(config-if-range)#switchport trunk encapsulation dot1q 
SW-2(config-if-range)#switchport mode trunk 
SW-2(config-if-range)#exit
//修改模式为Rapid-PVST(思科私有)
SW-2(config)#spanning-tree mode pvst 
//修改vlan的优先级
SW-2(config)#spanning-tree vlan 50 priority 4096
SW-2(config)#spanning-tree vlan 60 priority 0

SW-2(config)#interface vlan 50
SW-2(config-if)#ip address 192.168.50.2 255.255.255.0
SW-2(config-if)#no shutdown 
SW-2(config-if)#exit
SW-2(config)#interface vlan 60
SW-2(config-if)#ip address 192.168.60.2 255.255.255.0
SW-2(config-if)#no shutdown 
SW-2(config-if)#exit
//备份设备做HSRP相关配置。备份设备不用设置优先级,默认值100,只需在主设备设置比100大的值即可
SW-2(config)#interface vlan 50
SW-2(config-if)#standby version 2//版本
SW-2(config-if)#standby 50 ip 192.168.50.254
SW-2(config-if)#standby 50 preempt 
SW-2(config-if)#standby 50 timers 1 3//设置hello持有时间
SW-2(config-if)#exit
//SW-2是vlan 60的主设备,应当开启抢占延迟时间
SW-2(config)#interface vlan 60
SW-2(config-if)#standby version 2
SW-2(config-if)#standby 60 ip 192.168.60.254
SW-2(config-if)#standby 60 priority 105
SW-2(config-if)#standby 60 preempt 
SW-2(config-if)#standby 60 preempt delay minimum 60
SW-2(config-if)#standby 60 timers 1 3
SW-2(config-if)#exit
SW-2(config)#do show run interface vlan 50
Building configuration...

Current configuration : 155 bytes
!
interface Vlan50
 ip address 192.168.50.2 255.255.255.0
 standby version 2
 standby 50 ip 192.168.50.254
 standby 50 timers 1 3
 standby 50 preempt
end

SW-2(config)#do show run interface vlan 60//检查vlan 60的配置
Building configuration...

Current configuration : 197 bytes
!
interface Vlan60
 ip address 192.168.60.2 255.255.255.0
 standby version 2
 standby 60 ip 192.168.60.254
 standby 60 timers 1 3
 standby 60 priority 105
 standby 60 preempt delay minimum 60
end

SW-2(config)#do show standby brief 
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State   Active          Standby         Virtual IP
Vl50        50   100 P Standby 192.168.50.1    local           192.168.50.254
Vl60        60   105 P Active  local           192.168.60.1    192.168.60.254

SW-2(config)#vlan 20
SW-2(config-vlan)#exit
SW-2(config)#interface g0/3
SW-2(config-if)#switchport mode access   
SW-2(config-if)#switchport access vlan 20
SW-2(config-if)#exit
SW-2(config)#interface vlan 20
SW-2(config-if)#ip address 28.1.1.1 255.255.255.0
SW-2(config-if)#no shutdown 
SW-2(config-if)#exit
SW-2(config)#ip route 0.0.0.0 0.0.0.0 28.1.1.2
SW-2(config)#ip sla 1//定义SLA
SW-2(config-ip-sla)#icmp-echo 9.9.9.9 source-interface vlan 60//根据源与目的地检测链路状态
SW-2(config-ip-sla-echo)#frequency 5//设置发送ping包的时间间隔
SW-2(config-ip-sla-echo)#timeout 5000//设置时间,在此时间内未收到回复则认为链路故障
SW-2(config-ip-sla-echo)#exit
SW-2(config)#ip sla schedule 1 start-time now life forever //设置ping包的发送时间及持续时间
SW-2(config)#track 60 ip sla 1 reachability//创建track测试链路可达性
SW-2(config-track)#exit
SW-2(config)#interface vlan 60
SW-2(config-if)#standby 60 track 60 decrement 10//若出现故障则优先级减掉设置的数值(本文设置为10)
SW-2(config-if)#exit

SW-3

//封装接口
SW-3(config)#vlan 50
SW-3(config-vlan)#exit
SW-3(config)#interface g0/0
SW-3(config-if)#switchport mode access 
SW-3(config-if)#switchport access vlan 50
SW-3(config-if)#exit
SW-3(config)#interface range g0/1-2
SW-3(config-if-range)#switchport trunk encapsulation dot1q 
SW-3(config-if-range)#switchport mode trunk 
SW-3(config-if-range)#exit
//修改模式为Rapid-PVST(思科私有)
SW-3(config)#spanning-tree mode pvst 

SW-4

//封装接口
SW-4(config)#vlan 60
SW-4(config-vlan)#exit
SW-4(config)#interface g0/0
SW-4(config-if)#switchport mode access 
SW-4(config-if)#switchport access vlan 60
SW-4(config-if)#exit
SW-4(config)#interface range g0/1-2
SW-4(config-if-range)#switchport trunk encapsulation dot1q 
SW-4(config-if-range)#switchport mode trunk 
SW-4(config-if-range)#exit
//修改模式为Rapid-PVST(思科私有)
SW-4(config)#spanning-tree mode pvst 

R7

R7(config)#interface g0/0
R7(config-if)#ip address 17.1.1.2 255.255.255.0
R7(config-if)#no shutdown 
R7(config-if)#exit
R7(config)#interface g0/1
R7(config-if)#ip address 79.1.1.1 255.255.255.0
R7(config-if)#no shutdown 
R7(config-if)#exit
R7(config)#ip route 0.0.0.0 0.0.0.0 79.1.1.2
R7(config)#interface g0/0
R7(config-if)#ip nat inside 
R7(config-if)#exit
R7(config)#interface g0/1
R7(config-if)#ip nat outside 
R7(config-if)#exit
//命名式扩展ACL
R7(config)#ip access-list extended NAT
R7(config-ext-nacl)#permit ip 192.168.50.0 0.0.0.255 any
R7(config-ext-nacl)#permit ip 192.168.60.0 0.0.0.255 any
R7(config-ext-nacl)#exit
R7(config)#do show access-lists //查看抓取列表
Extended IP access list NAT
    10 permit ip 192.168.50.0 0.0.0.255 any
    20 permit ip 192.168.60.0 0.0.0.255 any
R7(config)#ip nat inside source list NAT interface g0/1 overload //调用
R7(config)#ip route 192.168.0.0 255.255.0.0 17.1.1.1

R8

R8(config)#interface g0/0
R8(config-if)#ip address 28.1.1.2 255.255.255.0
R8(config-if)#no shutdown 
R8(config-if)#exit
R8(config)#interface g0/1
R8(config-if)#ip address 89.1.1.1 255.255.255.0
R8(config-if)#no shutdown 
R8(config-if)#exit
R8(config)#ip route 0.0.0.0 0.0.0.0 89.1.1.2
R8(config)#interface g0/0
R8(config-if)#ip nat inside 
R8(config-if)#exit
R8(config)#interface g0/1
R8(config-if)#ip nat outside 
R8(config-if)#exit 
//命名式扩展ACL
R8(config)#ip access-list extended NAT 
R8(config-ext-nacl)#permit ip 192.168.50.0 0.0.0.255 any
R8(config-ext-nacl)#permit ip 192.168.60.0 0.0.0.255 any
R8(config-ext-nacl)#exit
R8(config)#ip nat inside source list NAT interface g0/1 overload 
R8(config)#ip route 192.168.0.0 255.255.0.0 28.1.1.1

R9

R9(config)#interface g0/1
R9(config-if)#ip address 89.1.1.2 255.255.255.0
R9(config-if)#no shutdown 
R9(config-if)#exit
R9(config)#interface g0/0
R9(config-if)#ip address 79.1.1.2 255.255.255.0
R9(config-if)#no shutdown 
R9(config-if)#exit
R9(config)#interface loopback 0
R9(config-if)#ip address 9.9.9.9 255.255.255.255
R9(config-if)#no shutdown 
R9(config-if)#exit

至此,网关热备份配置完成,已实现全网互通。
现在我们来让某个设备的端口down掉,来模拟网络链路出现故障的情况。观察主设备的情况。
以PC7为例,令PC7一直 ping 外网R3,在此期间将SW-1的G0/3接口down掉模拟链路故障,观察PC7的ping 信息。
PC7:

PC7#ping 9.9.9.9 repeat 1000

SW-1

SW-1(config)#interface g0/3
SW-1(config-if)#shutdown 

在这里插入图片描述
可见,在ping的期间链路出现故障后,存在短暂的数据断流,但由于HSRP的存在,当主设备出现故障时,备份设备立即成为新的主设备,从而使链路很快的恢复通信。

查看主备设备信息可发现,主设备出现故障,优先级降低变为95(先前配置时设置的减小值为10),从而使备份设备变为新的主设备:
在这里插入图片描述
traceroute查看路径:
在这里插入图片描述
可见,数据通过的路径已经切换,从SW-2上发送至外网。

重新打开刚刚关闭的端口,再次查看设备信息:
在这里插入图片描述
traceroute查看路径:
在这里插入图片描述
可见,链路恢复后主备设备重新切换回来,数据通过的路径也随之恢复为原先的路径。


总结

HSRP具有如下特点:
1.高度的可靠性,两台路由器之间采用HSRP(热备份冗余协议)协议,来保证两台路由器中的任意一台down掉,或路由器的广域网口down,都会迅速切换到另外一台。

2.有效的实现了负载均衡,在STAR-S1924F+上划分出各自的VLAN,储蓄子网VLAN在左侧路由器上的HSRP的优先级较高,默认使用网通的FR线路;邮政系统(办公、报刊、EMS、VOIP等等)子网VLAN在右侧路由器上的HSRP的优先级较高,默认使用联通的FR线路。充分利用了带宽资源,而且实现了负载均衡。

3.充分利用了多以太口路由器在划分多业务网段上的功能,也只有多以太口路由器在HSRP应用中才能实现两个路由器间的负载分担,这是具有四个以太口路由器的极大的优点。

4.在右侧路由器上启用QoS策略,VoIP业务需要较低的延时,所以将VoIP业务设置成较高的优先级。

5.通过在交换机上设置VLAN,有效的控制了两个子网间的安全。

6.不存在单点故障问题。

发布了29 篇原创文章 · 获赞 24 · 访问量 7822

猜你喜欢

转载自blog.csdn.net/zhang175gl/article/details/104474102