随着Internet的日益普及,人们对网络的依赖性也越来越强。这同时对网络的稳定性提出了更高的要求,人们自然想到了基于设备的备份结构,就像在服务器中为提高数据的安全性而采用双硬盘结构一样。路由器是整个网络的核心和心脏,如果路由器发生致命性的故障,将导致本地网络的瘫痪,如果是骨干路由器,影响的范围将更大,所造成的损失也是难以估计的。因此,对路由器采用热备份是提高网络可靠性的必然选择。在一个路由器完全不能工作的情况下,它的全部功能便被系统中的另一个备份路由器完全接管,直至出现问题的路由器恢复正常,这就是热备份路由协议(HotStandbyRouterProtocol),HSRP-RFC2281技术要解决的问题。

 
  HSRP工作原理:
 
  1.全称Hot Standby Routing Protocol,原理比较简单,类似于服务器HA群集,两台或更多的路由器以同样的方式配置成Cluster,创建出单个的虚拟路由器,然后客户端将网关指向该虚拟路由器。最好由HSRP决定哪个路由器扮演真正的默认网关。
  2.具体说,HRSP用于在源主机无法动态的学习到网关IP地址的情况下防止默认路由的失败。
  3.它主要用于多介入,多播和广播局域网(例如以太网)。
 
VRRP工作原理:
 
    虚拟路由器冗余协议(VRRP)是一种选择协议,它可以把一个虚拟路由器的责任动态分配到局域网上的 VRRP 路由器中的一台。控制虚拟路由器 IP 地址的 VRRP 路由器称为主路由器,它负责转发数据包到这些虚拟 IP 地址。一旦主路由器不可用,这种选择过程就提供了动态的故障转移机制,这就允许虚拟路由器的 IP 地址可以作为终端主机的默认第一跳路由器。使用 VRRP 的好处是有更高的默认路径的可用性而无需在每个终端主机上配置动态路由或路由发现协议。 VRRP 包封装在 IP 包中发送。
 
两者相互区别:
 
  1.VRRP协议的工作机理与CISCO公司的HSRP(Hot Standby Routing Protocol)有许多相似之处。但二者主要的区别是在CISCO的HSRP中,需要单独配置一个IP地址作为虚拟路由器对外体现的地址,这个地址不能是组中任何一个成员的接口地址。   
  2.使用VRRP协议,不用改造目前的网络结构,最大限度保护了当前投资,只需最少的管理费用,却大大提升了网络性能,具有重大的应用价值。
 
 
实验案例:

 
一.配置sw1:
 
  1.端口聚合:
sw1(config)#interface range fastEthernet 0/4
sw1(config-if-range)#channel-group 1 mode on
  2.创建vlan
sw1#vlan database
sw1(vlan)#vlan 10
sw1(vlan)#vlan 20
  3.指定端口类型:(trunk or access)
sw1(config)#interface fastEthernet 0/2
sw1(config-if)#switchport mode trunk
sw1(config)#interface fastEthernet 0/4
sw1(config-if)#switchport mode trunk
sw1(config)#interface fastEthernet 0/5
sw1(config-if)#switchport mode trunk
sw1(config-if)#interface fastEthernet 0/3
sw1(config-if)#switchport access vlan 10
 
二.配置sw2:
 
  1.端口聚合:
sw2(config)#interface range fastEthernet 0/4
sw1(config-if-range)#channel-group 1 mode on
  2.创建vlan
sw2#vlan database
sw2(vlan)#vlan 10
sw2(vlan)#vlan 20
  3.指定端口类型:(trunk or access)
sw2(config)#interface fastEthernet 0/2
sw2(config-if)#switchport mode trunk
sw2(config)#interface fastEthernet 0/4
sw1(config-if)#switchport mode trunk
sw1(config)#interface fastEthernet 0/5
sw1(config-if)#switchport mode trunk
sw2(config-if)#interface fastEthernet 0/3
sw2(config-if)#switchport access vlan 20
 
三.路由器 R-IN-2的配置:
 
  1.逻辑子接口:
R-IN-2(config-subif)#interface ethernet 0/2.10
R-IN-2(config-subif)#encapsulation dot1Q 10
R-IN-2(config-subif)#ip address 192.168.1.100   255.255.255.0
R-IN-2(config-subif)#interface ethernet 0/2.20
R-IN-2(config-subif)#encapsulation dot1Q 20
R-IN-2(config-subif)#ip address 192.168.2.200   255.255.255.0
  2.将逻辑子接口加入组,设置公共ip地址 
R-IN-2(config-subif)#inte ethernet 0/2.10
R-IN-2(config-subif)#standby 10 ip 192.168.1.254
R-IN-2(config-subif)#inte ethernet 0/2.20
R-IN-2(config-subif)#standby 20 ip 192.168.2.254
  3.配置接口优先级 作为主路由器,并添加抢占模式
R-IN-2(config-subif)#interface ethernet 0/2.20
R-IN-2(config-subif)#standby priority 130
R-IN-2(config-subif)#standby preempt
  4.跟踪端口 降低优先级(当端口阻塞时)
R-IN-2(config-subif)#interface ethernet 0/2.20
R-IN-2(config-subif)#standby  track 20 decrement 30
R-IN-2(config-subif)#interface ethernet 0/2.10
R-IN-2(config-subif)#standby  track 10 decrement 30
 
四.路由器 R-IN-1的配置:
 
  1.逻辑子接口:
R-IN-1(config-subif)#interface ethernet 0/2.10
R-IN-1(config-subif)#encapsulation dot1Q 10
R-IN-1(config-subif)#ip address 192.168.1.10   255.255.255.0
R-IN-1(config-subif)#interface ethernet 0/2.20
R-IN-1(config-subif)#encapsulation dot1Q 20
R-IN-1(config-subif)#ip address 192.168.2.20   255.255.255.0
  2.将逻辑子接口加入组,设置公共ip地址 
R-IN-1(config-subif)#inte ethernet 0/2.10
R-IN-1(config-subif)#standby 10 ip 192.168.1.254
R-IN-1(config-subif)#inte ethernet 0/2.20
R-IN-1(config-subif)#standby 20 ip 192.168.2.254
  3.配置接口优先级 作为主路由器,并添加抢占模式
R-IN-1(config-subif)#interface ethernet 0/2.10
R-IN-1(config-subif)#standby priority 130
R-IN-1(config-subif)#standby preempt
  4.跟踪端口 降低优先级(当端口阻塞时)
R-IN-1(config-subif)#interface ethernet 0/2.10
R-IN-1(config-subif)#standby  track 10 decrement 30
R-IN-1(config-subif)#interface ethernet 0/2.20
R-IN-1(config-subif)#standby  track 20 decrement 30
 
测试结果:
 
R-pc-1#pin g 192.168.2.254
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.254, timeout is 2 seconds
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
R-pc-2#ping 192.168.1.254
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.254, timeout is 2 seconds
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms