局域网中的用户终端通常采用配置一个默认网关的形式访问外部网络,如果此时默认网关设备发生故障,将中断所有用户终端的网络访问,这很可能会给用户带来不可预计的损失,那么可以通过部署多个网关的方式来解决单点故障问题。于是VRRP应运而生。
VRRP全称是虚拟路由器冗余协议(Virtual Ronter Redundancy Protocol),能够在不改变组网的情况下,将多台路由器虚拟成一个虚拟路由器,通过配置虚拟路由器的IP地址为默认网关,实现网关的备份。从而保证当主机的下一跳设备出现故障时,可以及时将业务切换到其他设备,从而保持通讯的连续性和可靠性。
协议版本:VRRPv2(常用)和VRRPv3
VRRPv2仅适用也IPV4网络,VRRPv3适用于IPV4和IPV3两种网络
VRRP只有一种报文Advertisement报文;其目的地址是224.0.0.18,目的MAC地址是01-00-5e-00-00-12,协议号是12.
如上图所示
1、对SW1进行配置
[SW1]v b 10 20
[SW1]int e0/0/1
[SW1-Ethernet0/0/1]p l a
[SW1-Ethernet0/0/1]p d v 10
[SW1-Ethernet0/0/1]un sh
[SW1-Ethernet0/0/1]int g0/0/2
[SW1-GigabitEthernet0/0/2]p l t
[SW1-GigabitEthernet0/0/2]p t a v 10 20
[SW1-GigabitEthernet0/0/2]un sh
[SW1-GigabitEthernet0/0/2]int e0/0/2
[SW1-Ethernet0/0/2]p l a
[SW1-Ethernet0/0/2]p d v 20
[SW1-Ethernet0/0/2]un sh
[SW1-Ethernet0/0/2]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l t
[SW1-GigabitEthernet0/0/1]p t a v 10 20
[SW1-GigabitEthernet0/0/1]un sh
2、配置SW2
[SW2]v b 10 20 100
[SW2]int g0/0/1
[SW2-GigabitEthernet0/0/1]p l t
[SW2-GigabitEthernet0/0/1]p t a v 10 20
[SW2-GigabitEthernet0/0/1]un sh
[SW2-GigabitEthernet0/0/1]int g0/0/2
[SW2-GigabitEthernet0/0/2]p l a
[SW2-GigabitEthernet0/0/2] p d v 100
[SW2-GigabitEthernet0/0/2]un sh
[SW2-GigabitEthernet0/0/2]int vlanif 10
[SW2-Vlanif10]ip add 192.168.10.10 24
[SW2-Vlanif10]un sh
[SW2-Vlanif10]int vlanif 20
[SW2-Vlanif20]ip address 192.168.20.10 24
[SW2-Vlanif20]int vlanif 100
[SW2-Vlanif100]ip add 11.0.0.2 30
[SW2-Vlanif100]un sh
[SW2]ip route-static 0.0.0.0 0.0.0.0 11.0.0.1
[SW2]int vlanif 10
[SW2-Vlanif10]vrrp vrid 1 virtual-ip 192.168.10.1###配置虚拟IP地址
[SW2-Vlanif10]vrrp vrid 1 priority 120###配置优先级
[SW2-Vlanif10]vrrp vrid 1 track interface g0/0/1###配置监听端口,当这个地方down时,优先级减10
[SW2-Vlanif10]vrrp vrid 1 track interface g0/0/2
[SW2-Vlanif10]int vlanif 20
[SW2-Vlanif20]vrrp vrid 2 virtual-ip 192.168.20.1
[SW2-Vlanif20]vrrp vrid 2 priority 115
3、配置SW3
[SW3]v b 10 20 100
[SW3]int g0/0/1
[SW3-GigabitEthernet0/0/1]p l t
[SW3-GigabitEthernet0/0/1]p t a v 10 20
[SW3-GigabitEthernet0/0/1]int g0/0/2
[SW3-GigabitEthernet0/0/2]p l a
[SW3-GigabitEthernet0/0/2]p d v 100
[SW3-GigabitEthernet0/0/2]un sh
[SW3-GigabitEthernet0/0/2]int vlanif 10
[SW3-Vlanif10]ip add 192.168.10.20 24
[SW3-Vlanif10]int vlanif 20
[SW3-Vlanif20]ip add 192.168.20.20 24
[SW3-Vlanif20]int vlanif 100
[SW3-Vlanif100]ip add 12.0.0.2 30
[SW3-Vlanif100]un sh
[SW3]int vlanif 10
[SW3-Vlanif10]vrrp vrid 1 virtual-ip 192.168.10.1
[SW3-Vlanif10]vrrp vrid 1 priority 115
[SW3-Vlanif10]int vlanif 20
[SW3-Vlanif20]vrrp vrid 2 virtual-ip 192.168.20.1
[SW3-Vlanif20]vrrp vrid 2 priority 120
[SW3-Vlanif20]vrrp vrid 2 track interface g0/0/1
[SW3-Vlanif20]vrrp vrid 2 track interface g0/0/2
4、配置R1
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 11.0.0.1 30
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 12.0.0.1 30
[R1-GigabitEthernet0/0/1]int loo 0
[R1-LoopBack0]ip add 1.1.1.1 24
[R1]ip route-static 192.168.10.0 24 11.0.0.2
[R1]ip route-static 192.168.10.0 24 12.0.0.2 preference 70
[R1]ip route-static 192.168.20.0 24 12.0.0.2
[R1]ip route-static 192.168.20.0 24 11.0.0.2 preference 70
5、这样完整的实验配置就完成了,当然最后我们少不了检验了
在PC1 ping 1.1.1.1
我们断开个g0/0/0的接口,看数据是否可以流通
继续ping 1.1.1.1