一:vrrp简介:
1:不同网段之间通信, 必须通过自己设定了网关或者代理服务器。 然而,在实际的网络应用中,尤其是一些大型网络, 要求网络服务器质量严格的企业里,终端指定的网关往往因为某种意外而宕掉, 不能及时切换到另外一个可用的网关上, 造成网 络断开。VRRP(虚拟路由器冗余协议)是一种备份冗余解决方案,它共享多路访问介质(如以太网)上终端ip设备的默认网关,并进行冗余备份,从而在其中一台路由设备宕机时,备份路由设备能够及时接管转发工作,为用户提供透明的切换,提高网络服务质量。
2:vrrp状态:
initialize状态:系统启动后进入initialize状态,路由器不对vrrp报文做任何处理。当收到接口up的消息后,将进入backup或master状态 
master状态:
(1)定期发送vrrp通告;
(2)发送免费ARP报文,以便网络内个主机知道虚拟ip地址所对应的虚拟mac地址;
(3)响应虚拟ip地址的ARP请求,且响应的是虚拟mac地址,不是接口的真是mac地址;
(4)转发目的mac地址为虚拟mac地址的ip报文(5):如果路由器是虚拟ip地址的拥有者,则接收目的ip地址为虚拟ip地址的报文,否则丢弃ip报文。
backup状态有:
(1)接收master发送的vrrp报文,从中了解master的状态;
(2)对虚拟ip地址的ARP请求不做响应;
(3)丢弃目的mac地址为虚拟mac地址的ip报文;
(4)丢弃目的ip地址为虚拟ip地址的ip报文。

二:HSRP简介:
1:热备份路由器协议(HSRP)的设计目标是支持特定情况下 IP 流量失败转移不会引起混乱、并允许主机使用单路由器,以及即使在实际第一跳路由器使用失败的情形下仍能维护路由:器间的连通性。换句话说,当源主机不能动态知道第一跳路由器的 IP 地址时,HSRP 协议能够保护第一跳路由器不出故障。
2:hsrp状态:
初始状态(initial):接口初次启动或者配置变更后进入此状态 
学习状态(learn):路由器尚未确定虚拟IP地址,未从活动路由器接收到需要鉴权的helllo消息,等待活动路由器的消息。 
监听状态(listen):路由器知道了虚拟IP地址,但自己不是活动或是备份路由器,此时监听来自活动和备份路由器的hello消息。 
发言状态(speak):路由器定时发送hello消息,积极参与竞选,无虚拟IP地址的路由器将无法参与选举。 
备份状态(standby):路由器候选成为下一个活动路由器,它会定时发送hello消息,一组最多只有一个备份路由器。 
活动状态(active):此状态的路由器负责转发发往改组的虚拟MAC地址的数据包,定时发送hello消息,一组最多只有一台活动路由器。 
三:vrrp与hsrp的相同点与不同点:
1、两个都支持认证 
2、两个都支持抢占,VRRP抢占默认开启 
3、都可以做负载均衡(不同组之间)
4、HSRP中路由状态有6中,VRRP有3种
5、HSRP中叫做active路由器和standby路由器,VRRP叫做master路由器和backup路由器。HSRP是cisco私有,VRRP公有
6、HSRP standby路由器也主动发送hello包,这样HSRP活动路由器可以发现网络当中的备份路由器 VRRP backup路由器不主动发送hello包,所以master路由器不可以主动发现网络当中的backup路由器 。
7、HSRP虚拟路由器的Ip不能是活动路由器接口的ip,VRRP可以
8、HSRP支持追踪,VRRP不支持追踪 
9、HSRP的standby路由器选举只有优先级起作用,ip地址不起作用。 VRRP的活动路由器选举优先级和ip地址都起作用 
10、HSRP的hello时间为3秒,间隔hold时间为10秒 VRRP中失效间隔时间是通告间隔时间的3倍,通告间隔时间默认1秒 
11、VRRP支持辞职,HSRP不支持辞职(辞职是指将接口优先级改为0后不参加活动路由器的选举) 
12、虚拟MAC:00-00-5e-00-01-01 VRRP  组播地址224.0.0.18 00-00-0c-07-ac-01 HSRP  组播地址 224.0.0.2

案例:


案例一:VRRP实现负载均衡:
拓扑方案:

image


配置:

R1配置:

[R1]int e0.1
[R1-Ethernet0.1]vlan-type dot1q vid 10
[R1-Ethernet0.1]ip add 192.168.10.1 24
[R1-Ethernet0.1]int e0.2             
[R1-Ethernet0.2]vlan-type dot1q vid 20
[R1-Ethernet0.2]ip add 192.168.20.1 24

[R1]vrrp ping-enable
[R1]int e0.1
[R1-Ethernet0.1]vrrp vrid 10 virtual-ip 192.168.10.254
[R1-Ethernet0.1]vrrp vrid 10 peioeity 120
[R1-Ethernet0.1]int e0.2
[R1-Ethernet0.2]vrrp vrid 20 virtual-ip 192.168.20.254

R2配置:

[R2]int e0.1
[R2-Ethernet0.1]vlan-type dot1q vid 10
[R2-Ethernet0.1]ip add 192.168.10.2 24
[R2-Ethernet0.1]int e0.2             
[R2-Ethernet0.2]vlan-type dot1q vid 20
[R2-Ethernet0.2]ip add 192.168.20.2 24

[R2]vrrp ping-enable
[R2]int e0.1
[R2-Ethernet0.1]vrrp vrid 10 virtual-ip 192.168.10.254
[R2-Ethernet0.1]int e0.2
[R2-Ethernet0.2]vrrp vrid 20 virtual-ip 192.168.20.254
[R2-Ethernet0.2]vrrp vrid 20 peioeity 120

SW1配置:

[SW1]int eth 0/2
[SW1-Ethernet0/2]port link-type trunk
[SW1-Ethernet0/2]port trunk permit vlan all
[SW1-Ethernet0/2]int eth 0/1
[SW1-Ethernet0/1]port link-type trunk
[SW1-Ethernet0/1]port trunk permit vlan all
[SW1-Ethernet0/1]quit
[SW1]vlan 10
[SW1-vlan10]port e0/5 to e0/10
[SW1-vlan10]vlan 20
[SW1-vlan20]port e0/11 to e0/15

SW2配置:

[SW2]int e0/2   
[SW2-Ethernet0/2]port link-type trunk
[SW2-Ethernet0/2]port trunk permit vlan all
[SW2-Ethernet0/2]int e0/1
[SW2-Ethernet0/1]port link-type trunk     
[SW2-Ethernet0/1]port trunk permit vlan all
[SW2-Ethernet0/1]quit
[SW2]vlan 10
[SW2-vlan10]port e0/5 to e0/10
[SW2-vlan10]vlan 20
[SW2-vlan20]port e0/11 to e0/15

验证:

R1正常时进行跟踪数据传输:

clip_image001

clip_image002

R1断开之后进行跟踪数据传输:

clip_image003

clip_image005

查看Vlan的配置信息,SW2相同:

clip_image006


案例二:HSRP实现负载均衡:


拓扑方案:

image
配置:

R1配置:

R1(config)#int f0/0.10
R1(config-subif)#encapsulation dot1Q 10
R1(config-subif)#ip add 192.168.10.1 255.255.255.0 
R1(config-subif)#no shutdown
R1(config-subif)#standby 10 ip 192.168.10.254
R1(config-subif)#standby 10 priority 120
R1(config-subif)#int f0/0.20
R1(config-subif)#encapsulation dot1Q 20
R1(config-subif)#ip add 192.168.20.1 255.255.255.0
R1(config-subif)#no shutdown
R1(config-subif)#standby 20 ip 192.168.20.254

R2配置:

R2(config)#int f0/0.10
R2(config-subif)#encapsulation dot1Q 10
R2(config-subif)#ip add 192.168.10.1 255.255.255.0 
R2(config-subif)#no shutdown
R2(config-subif)#standby 10 ip 192.168.10.254
R2(config-subif)#int f0/0.20
R2(config-subif)#encapsulation dot1Q 20
R2(config-subif)#ip add 192.168.20.1 255.255.255.0
R2(config-subif)#no shutdown
R2(config-subif)#standby 20 ip 192.168.20.254
R2(config-subif)#standby 20 priority 120

SW1配置:

SW1(config)#int f0/0
SW1(config-if)#switchport mode trunk 
SW1(config)#int f0/1
SW1(config-if)#switchport mode trunk 
SW1#vlan database
SW1(vlan)#vlan 10
SW1(vlan)#vlan 20
SW1(vlan)#exit
SW1(config)#int range f0/5 - 10     
SW1(config-if-range)#switchport access vlan 10
SW1(config)#int range f0/11 - 15
SW1(config-if-range)#switchport access vlan 20

SW2配置:

SW2(config)#int f0/0
SW2(config-if)#switchport mode trunk 
SW2(config)#int f0/1
SW2(config-if)#switchport mode trunk 
SW2#vlan database
SW2(vlan)#vlan 10
SW2(vlan)#vlan 20
SW2(vlan)#exit
SW2(config)#int range f0/5 - 10     
SW2(config-if-range)#switchport access vlan 10
SW2(config)#int range f0/11 - 15
SW2(config-if-range)#switchport access vlan 20


验证:

image

image

R1正常情况,进行跟踪数据传输:

image

image

断开R1之后,进行跟踪数据传输:

image

image