作者:信妹氵V | 来源:互联网 | 2023-10-11 08:08
一、简介
虚拟路由器冗余协议(VRRP)是一种选择协议,它可以把一个虚拟路由器的责
任动态分配到局域网上的 VRRP 路由器中的一台。控制虚拟路由器 IP 地址的VRRP
路由器称为主路由器,它负责转发数据包到这些虚拟 IP 地址。一旦主路由器不可
用,这种选择过程就提供了动态的故障转移机制,这就允许虚拟路由器的 IP 地址可
以作为终端主机的默认第一跳路由器。使用 VRRP 的好处是有更高的默认路径的可
用性而无需在每个终端主机上配置动态路由或路由发现协议。 VRRP 包封装在 IP
包中发送,是一种LAN接入设备备份协议。一个局域网络内的所有主机都设置缺省
网关,这样主机发出的目的地址不在本网段的报文将被通过缺省网关发往三层交换
机,从而实现了主机和外部网络的通信。
工作原理
VRRP只定义了一种报文——vrrp报文,这是一种组播报文,由主三层交换机定
时发出来通告他的存在。使用这些报文可以检测虚拟三层交换机各种参数,还可以
用于主三层交换机的选举。
VRRP中定义了三种状态模型,初始状态Initialize,活动状态Master和备份状态
Backup,其中只有活动状态的交换机可以为到虚拟IP地址的的转发请求提供服务。
VRRP报文是封装在IP报文上的,支持各种上层协议,同时VRRP还支持将真实
接口IP地址设置为虚拟IP地址。
那么如何从备份组的多台交换机中选举Master?这项工作由我们在备份组内每台
交换机上配置的相同IP地址的虚拟交换机完成。
虚拟交换机根据配置的优先级的大小选择主交换机,优先级最大的作为主交换
机,状态为Master,若优先级相同(如果交换机没有配置优先级,就采用默认值
100),则比较接口的主IP地址,主IP地址大的就成为主交换机,由它提供实际的路
由服务。其他交换机作为备份交换机,随时监测主交换机的状态。当主交换机正常
工作时,它会每隔一段时间发送一个VRRP组播报文,以通知组内的备份交换机,主
交换机处于正常工作状态。如果组内的备份交换机长时间没有接收到来自主交换机
的VRRP组播报文,则将自己状态转换为Master。当组内有多台备份交换机,将有可
能产生多个主交换机。这时每一个主交换机就会比较VRRP报文中的优先级和自己本
地的优先级,如果本地的优先级小于VRRP中的优先级,则将自己的状态转换为
Backup,否则保持自己的状态不变。通过这样一个过程,就会将优先级最大的交换
机选成新的主交换机,完成VRRP的备份功能。
二层交换机lsw3配置
undo terminal monitor
Info: Current terminal monitor is off.
sys
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname lsw3
[lsw3]user-in
[lsw3]user-interface con
[lsw3]user-interface console 0
[lsw3-ui-console0]id
[lsw3-ui-console0]idle-timeout 0 0
[lsw3-ui-console0]q
[lsw3]vlan b
[lsw3]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[lsw3]int e0/0/1
[lsw3-Ethernet0/0/1]p l a
[lsw3-Ethernet0/0/1]p d v 10
[lsw3-Ethernet0/0/1]int e0/0/2
[lsw3-Ethernet0/0/2]p l a
[lsw3-Ethernet0/0/2]p d v 20
[lsw3-Ethernet0/0/2]int g0/0/1
[lsw3-GigabitEthernet0/0/1]p l t
[lsw3-GigabitEthernet0/0/1]p t a v 10 20
[lsw3-GigabitEthernet0/0/1]int g0/0/2
[lsw3-GigabitEthernet0/0/2]p l t
[lsw3-GigabitEthernet0/0/2]p t a v 10 20
三层交换机 lsw1 配置
undo terminal monitor
Info: Current terminal monitor is off.
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname lsw1
[lsw1]user-interface console 0
[lsw1-ui-console0]idle-timeout 0 0
[lsw1-ui-console0]q
[lsw1]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[lsw1]vlan 100
[lsw1-vlan100]q
[lsw1]int g0/0/2
[lsw1-GigabitEthernet0/0/2]p l t
[lsw1-GigabitEthernet0/0/2]p t a v 10 20
[lsw1-GigabitEthernet0/0/2]un sh
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[lsw1-GigabitEthernet0/0/2]int g0/0/1
[lsw1-GigabitEthernet0/0/1]p l a
[lsw1-GigabitEthernet0/0/1]p d v 100
[lsw1-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[lsw1-GigabitEthernet0/0/1]q
[lsw1]int vlanif 10
[lsw1-Vlanif10]ip add 192.168.10.10 24
[lsw1-Vlanif10]vrrp vr
[lsw1-Vlanif10]vrrp vrid ?
INTEGER<1-255> Virtual router identifier
[lsw1-Vlanif10]vrrp vrid 1?
INTEGER<1-255>
[lsw1-Vlanif10]vrrp vrid 1 vir
[lsw1-Vlanif10]vrrp vrid 1 virtual-ip 192.168.10.1 配置虚拟的ip地址
[lsw1-Vlanif10]vrrp vrid 1 priority 120 配置优先级
[lsw1-Vlanif10]vrrp vrid 1 track interface g0/0/1 配置监听端口
[lsw1-Vlanif10]vrrp vrid 1 track interface g0/0/2
[lsw1-Vlanif10]int vlanif 20
[lsw1-Vlanif20]ip add 192.168.20.10 24
[lsw1-Vlanif20]vrr
[lsw1-Vlanif20]vrrp vi
[lsw1-Vlanif20]vrrp vr
[lsw1-Vlanif20]vrrp vrid 2 vi
[lsw1-Vlanif20]vrrp vrid 2 virtual-ip 192.168.20.1
[lsw1-Vlanif20]vrrp v
[lsw1-Vlanif20]vrrp vrid 2 p
[lsw1-Vlanif20]vrrp vrid 2 pr
[lsw1-Vlanif20]vrrp vrid 2 priority 115
[lsw1-Vlanif20]q
[lsw1]int vlanif 100
[lsw1-Vlanif100]ip add 11.0.0.2 30
[lsw1-Vlanif100]q
[lsw1]ip r
[lsw1]ip rou
[lsw1]ip route-s
[lsw1]ip route-static 0.0.0.0 0.0.0.0 11.0.0.1
三层交换机lsw2命令配置
system-view
Enter system view, return user view with Ctrl&#43;Z.
[Huawei]sysname LSW2
[LSW2]user-in
[LSW2]user-interface con
[LSW2]user-interface console 0
[LSW2-ui-console0]id
[LSW2-ui-console0]idle-timeout 0 0
[LSW2-ui-console0]q
[LSW2]vlan b
[LSW2]vlan batch 10 20 100
Info: This operation may take a few seconds. Please wait for a moment...done.
[LSW2]int g0/0/2
[LSW2-GigabitEthernet0/0/2]p l t
[LSW2-GigabitEthernet0/0/2]p t a v 10 20
[LSW2-GigabitEthernet0/0/2]un sh
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[LSW2-GigabitEthernet0/0/2]int g0/0/1
[LSW2-GigabitEthernet0/0/1]p l a
[LSW2-GigabitEthernet0/0/1]p d v 100
[LSW2-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[LSW2-GigabitEthernet0/0/1]int vlanif 10
[LSW2-Vlanif10]ip add 192.168.10.20 24
[LSW2-Vlanif10]vrrp vrid 1 priority 115
Error: The VRRP does not exist.
[LSW2-Vlanif10]int vlanif 20
[LSW2-Vlanif20]ip add 192.168.20.20 24
[LSW2-Vlanif20]vrrp vrid 2
[LSW2-Vlanif20]vrrp vrid 2 vi
[LSW2-Vlanif20]vrrp vrid 2 virtual-ip 192.168.20.1
[LSW2-Vlanif20]vrrp vrid 2 priority 120
[LSW2-Vlanif20]vrrp vrid 2 track interface g0/0/2
[LSW2-Vlanif20]int vlan
[LSW2-Vlanif20]int vlani
[LSW2-Vlanif20]int vlanif 100
[LSW2-Vlanif100]ip add 12.0.0.2 30
[LSW2-Vlanif100]q
[LSW2]ip r
[LSW2]ip rou
[LSW2]ip route-s
[LSW2]ip route-static 0.0.0.0 0.0.0.0 12.0.0.1
[LSW2]
路由器 R1
undo terminal monitor
Info: Current terminal monitor is off.
sys
system-view
Enter system view, return user view with Ctrl&#43;Z.
[Huawei]sysname R1
[R1]user-interface console 0
[R1-ui-console0]idle-timeout 0 0
[R1-ui-console0]q
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 11.0.0.1 30
[R1-GigabitEthernet0/0/0]un sh
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 12.0.0.1 30
[R1-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R1-GigabitEthernet0/0/1]int loo 0
[R1-LoopBack0]ip add 1.1.1.1 24
[R1-LoopBack0]q
[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 p
[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