INITIALIZE状态的作用:
路由器启动时,如果路由器的优先级是255(最高优先级,当且仅当配置的VRRP虚拟IP地址和接口IP相同,即所谓IP地址拥有者),要发送VRRP通告信息,并发送广播ARP信息通告路由器IP地址对应的MAC地址为路由虚拟MAC,设置通告信息定时器准备定时发送VRRP通告信息,转为MASTER状态:否则进入BACKUP状态,设置定时器检查定时检查是否收到MASTER的通告信息。
MASTER状态的作用:
●设置定时通告定时器;
●用VRRP虚拟MAC地址响应路由器IP地址的ARP请求;
●转发目的MAC是VRRP虚拟MAC的数据包;
●如果是虚拟路由器IP的拥有者,将接受目的地址是虚拟路由器IP的数据包,否则丢弃;
●当收到shutdown的事件时删除定时通告定时器,发送优先值级为0的通告包,转初始化状态;
●如果定时通告定时器超时时,发送VRRP通告信息;
●收到VRRP通告信息时,如果优先值为0,发送VRRP通告信息:否则,判断数据的优先级是否高于本机,或相等而且实际IP地址大于本地实际IP,设置定时通告定时器,复位主机超时定时器,转BACKUP状态;否则的话,丢弃该通告包。
BACKUP状态的作用
●设置主机超时定时器;
●不能响应针对虚拟路由器IP的ARP请求信息;
●丢弃所有目的MAC地址是虚拟路由器MAC地址的数据包;
●不接受目的是虚拟路由器IP的所有数据包;
●当收到shutdown的事件时删除主机超时定时器,转初始化状态;
●主机超时定时器超时的时候,发送VRRP通告信息,广播ARP地址信息,转MASTER状态;
●收到VRRP通告信息时。如果优先值为0,表示进入与MASTER选举,否则判断数据的优先级是否高于本机,如果高的话承认MASTER有效,复位主机超时定时器;否则的话,丢弃该通告包。
网络拓补图
二层交换机的配置
sys
#关闭信息提示
[Huawei]un in en
#创建vlan
[Huawei]v b 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
#配置access接口
[Huawei]int e0/0/1
[Huawei-Ethernet0/0/1]p l a
[Huawei-Ethernet0/0/1]p d v 10
[Huawei-Ethernet0/0/1]un sh
Info: Interface Ethernet0/0/1 is not shutdown.
[Huawei-Ethernet0/0/1]int e0/0/2
[Huawei-Ethernet0/0/2]p l a
[Huawei-Ethernet0/0/2]p d v 20
[Huawei-Ethernet0/0/2]un sh
Info: Interface Ethernet0/0/2 is not shutdown.
#配置trunk接口
[Huawei-Ethernet0/0/2]int g0/0/2
[Huawei-GigabitEthernet0/0/2]p l t
[Huawei-GigabitEthernet0/0/2]p t a v 10 20
[Huawei-GigabitEthernet0/0/2]un sh
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[Huawei-GigabitEthernet0/0/2]int g0/0/1
[Huawei-GigabitEthernet0/0/1]p l t
[Huawei-GigabitEthernet0/0/1]p t a v 10 20
[Huawei-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[Huawei-GigabitEthernet0/0/1] User interface con0 is available
三层交换机的配置
LSW1
sys
Enter system view, return user view with Ctrl+Z.
#关闭信息提示
[Huawei]un in en
Info: Information center is disabled.
#配置vlan
[Huawei]vlan bat 10 20 100
Info: This operation may take a few seconds. Please wait for a moment...done.
#配置access接口
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]p l t
[Huawei-GigabitEthernet0/0/1]p t a v 10 20
[Huawei-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[Huawei-GigabitEthernet0/0/1]int g0/0/2
[Huawei-GigabitEthernet0/0/2]p l a
[Huawei-GigabitEthernet0/0/2]p d v 100
[Huawei-GigabitEthernet0/0/2]un sh
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[Huawei-GigabitEthernet0/0/2]q
#配置虚拟子接口
[Huawei]int Vlanif 10
[Huawei-Vlanif10]ip add 192.168.10.10 24
#配置网关
[Huawei-Vlanif10]vrrp vrid 1 virtual-ip 192.168.10.1
#配置vrrp的优先级,数字越大,优先级越高 ,配置pc1的master
[Huawei-Vlanif10]vrrp vrid 1 priority 120
#配置监控接口
[Huawei-Vlanif10]vrrp vrid 1 track int g0/0/1
[Huawei-Vlanif10]vrrp vrid 1 track int g0/0/2
[Huawei-Vlanif10]q
#配置vlan20的虚拟子接口
[Huawei]int Vlanif 20
[Huawei-Vlanif20]ip add 192.168.20.10 24
#配置网关
[Huawei-Vlanif20]vrrp vrid 2 virtual-ip 192.168.20.1
#配置pc2的备份vrrp
[Huawei-Vlanif20]vrrp vrid 2 priority 115
[Huawei-Vlanif20]q
#【配置vlan100的IP地址
[Huawei]int Vlanif 100
[Huawei-Vlanif100]ip add 11.0.0.2 24
[Huawei-Vlanif100]q
#配置通往路由器的默认路由
[Huawei]ip route-static 0.0.0.0 0.0.0.0 11.0.0.1
#查看vrrp配置
[Huawei]dis vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 192.168.10.1
Master IP : 192.168.10.10
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Track IF : GigabitEthernet0/0/1 Priority reduced : 10
IF state : UP
Track IF : GigabitEthernet0/0/2 Priority reduced : 10
IF state : UP
Create time : 2019-12-18 11:26:30 UTC-08:00
Last change time : 2019-12-18 11:26:50 UTC-08:00
Vlanif20 | Virtual Router 2
State : Backup
Virtual IP : 192.168.20.1
Master IP : 192.168.20.20
PriorityRun : 115
PriorityConfig : 115
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0102
Check TTL : YES
Config type : normal-vrrp
Create time : 2019-12-18 11:27:44 UTC-08:00
Last change time : 2019-12-18 11:27:44 UTC-08:00
LSW2配置
sys
#关闭信息提示
[Huawei]un in en
Info: Information center is disabled.
#配置vlan
[Huawei]v b 10 20 100
#配置access接口
[Huawei]int g0/0/2
[Huawei-GigabitEthernet0/0/2]p l t
[Huawei-GigabitEthernet0/0/2]p t a v 10 20
[Huawei-GigabitEthernet0/0/2]un sh
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[Huawei-GigabitEthernet0/0/2]int g0/0/1
[Huawei-GigabitEthernet0/0/1]p l a
[Huawei-GigabitEthernet0/0/1]p d v 100
[Huawei-GigabitEthernet0/0/1]un sh
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[Huawei-GigabitEthernet0/0/1]q
#配置虚拟子接口vlan10
[Huawei]int Vlanif 10
[Huawei-Vlanif10]ip add 192.168.10.20 24
#配置网关
[Huawei-Vlanif10]vrrp vrid 1 virtual-ip 192.168.10.1
#配置pc1的备份vrrp
[Huawei-Vlanif10]vrrp vrid 1 priority 115
[Huawei-Vlanif10]q
#配置虚拟子接口vlan20
[Huawei]int Vlanif 20
[Huawei-Vlanif20]ip add 192.168.20.20 24
#配置网关
[Huawei-Vlanif20]vrrp vrid 2 virtual-ip 192.168.20.1
#配置pc2的master
[Huawei-Vlanif20]vrrp vrid 2 priority 120
#配置监控接口
[Huawei-Vlanif20]vrrp vrid 2 track interface g0/0/1
[Huawei-Vlanif20]vrrp vrid 2 track interface g0/0/2
[Huawei-Vlanif20]q
#配置vlan100的虚拟子口
[Huawei]int Vlanif 100
[Huawei-Vlanif100]ip add 12.0.0.2 24
[Huawei-Vlanif100]q
#配置通向路由的默认路由协议
[Huawei]ip route-static 0.0.0.0 0.0.0.0 12.0.0.1
#查看vrrp配置
[Huawei]dis vrrp
Vlanif10 | Virtual Router 1
State : Backup
Virtual IP : 192.168.10.1
Master IP : 192.168.10.10
PriorityRun : 115
PriorityConfig : 115
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2019-12-18 10:37:14 UTC-08:00
Last change time : 2019-12-18 11:13:30 UTC-08:00
Vlanif20 | Virtual Router 2
State : Master
Virtual IP : 192.168.20.1
Master IP : 192.168.20.20
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0102
Check TTL : YES
Config type : normal-vrrp
Track IF : GigabitEthernet0/0/1 Priority reduced : 10
IF state : UP
Track IF : GigabitEthernet0/0/2 Priority reduced : 10
IF state : UP
Create time : 2019-12-18 10:37:59 UTC-08:00
Last change time : 2019-12-18 10:38:03 UTC-08:00
R1的配置
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]un in en
Info: Information center is disabled.
[Huawei]int g0/0/2
[Huawei-GigabitEthernet0/0/2]ip add 11.0.0.1 24
[Huawei-GigabitEthernet0/0/2]un sh
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[Huawei-GigabitEthernet0/0/2]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 12.0.0.1 24
[Huawei-GigabitEthernet0/0/1]un sh
[Huawei-GigabitEthernet0/0/1]q
#配置回环地址
[Huawei]int loo 0
[Huawei-LoopBack0]ip add 2.2.2.2 32
[Huawei-LoopBack0]q
#配置浮动路由
[Huawei]ip route-static 192.168.10.0 24 11.0.0.2
[Huawei]ip route-static 192.168.10.0 24 12.0.0.2 preference 70
[Huawei]ip route-static 192.168.20.0 24 12.0.0.2
[Huawei]ip route-static 192.168.20.0 24 11.0.0.2 preference 70
用pc1 ping 2.2.2.2
用pc2 ping 2.2.2.2
断开LSW1的g0/0/2接口,再用pc1 ping 2.2.2.2