VRRP工作原理
简介:
VRRP:(Virtual Router Redundancy Protocol)虚拟路由器冗余协议
主用路由器master:负责转发发给虚拟路由器的数据包,并响应ARP请求的路由器。若一台拥有与虚拟路由器有相同IP地址的VRRP路由器(IP拥有者)活动,则此VRRP路由器为主用路由器。
备用路由器backup:在VRRP中,其他参与此虚拟路由器的均为备用路由器。它将在主用路由器不能工作时接替其工作。
工作机制:
VRRP协议通过发送协议报文来进行主、备关系的选举;协议报文主要是用来传递VRRP路由器优先级、主用路由器状态(含有VRID、VIP)等信息,通过组播通讯(224.0.0.18);每个虚拟路由器组有一个 VRID, 它定义了此组的所有成员;为减少网络流量,只有主用路由器可以定期发布VRRP广告消息,若备用路由器在一段时间内未收到来自主用路由器的广告,便自动转换到主用状态,并将自己广告出去。主用路由器会根据vrid生成虚拟mac,00005e0001xx,作为vip的mac地址,并通过发送arp报文通告给网络中的设备;若主用路由器不能工作,则优先级最高的备用路由器将接替主用路由器工作(很短的延时),作为有效的虚拟路由器转发数据包;VRRP仅在本网段有效,其他网段的通信与其无关。
案例一
实验设备:华为(两台路由器、两台交换机、两台物理主机)
实验拓扑图:
路由器r1配置:
- r1]inter e1.10
- [r1-Ethernet1.10]vlan-type dot1q vid 10 //封装dot1q协议
- [r1-Ethernet1.10]ip add 192.168.10.1 255.255.255.0 //配置子接口地址
- [r1-Ethernet1.10]inter e1.20
- [r1-Ethernet1.20]vlan-type dot1q vid 20
- [r1-Ethernet1.20]ip add 192.168.20.1 255.255.255.0
- [r1-Ethernet1.20]quit
- [r1]vrrp ping-enable //启动ping vrrp (配置前要先启动)
- [r1]inter e1.10
- [r1-Ethernet1.10]vrrp vrid 10 virtual-ip 192.168.10.254 //配置虚拟ip地址
- [r1-Ethernet1.10]vrrp vrid 10 priority 130 //设置优先级
- [r1-Ethernet1.10]inter e1.20
- [r1-Ethernet1.20]vrrp vrid 20 virtual-ip 192.168.20.254
- [r1-Ethernet1.20]vrrp vrid 20 priority 120
查看配置结果:
- [r1]dis cu
- interface Ethernet1.10
- vlan-type dot1q vid 10
- ip address 192.168.10.1 255.255.255.0
- vrrp vrid 10 virtual-ip 192.168.10.254
- vrrp vrid 10 priority 130
- !
- interface Ethernet1.20
- vlan-type dot1q vid 20
- ip address 192.168.20.1 255.255.255.0
- vrrp vrid 20 virtual-ip 192.168.20.254
- vrrp vrid 20 priority 120
查看vrrp信息:
- [r1]dis vrrp
- Ethernet1.20 | Virtual Router 20
- state : Master
- Virtual IP : 192.168.20.254
- Priority : 120
- Preempt : YES Delay Time : 0
- Timer : 1
- Auth Type : NO
- Ethernet1.10 | Virtual Router 10
- state : Master
- Virtual IP : 192.168.10.254
- Priority : 130
- Preempt : YES Delay Time : 0
- Timer : 1
- Auth Type : NO
路由器r2配置:
- [r2]inter e1.10
- [r2-Ethernet1.10]vlan-type dot1q vid 10
- [r2-Ethernet1.10]ip add 192.168.10.2 255.255.255.0
- [r2-Ethernet1.10]inter e1.20
- [r2-Ethernet1.20]vlan-type dot1q vid 20
- [r2-Ethernet1.20]ip add 192.168.20.2 255.255.255.0
- [r2-Ethernet1.20]quit
- [r2]vrrp ping-e
- [r2]inter e1.10
- [r2-Ethernet1.10]vrrp vrid 10 virtual-ip 192.168.10.254
- [r2-Ethernet1.10]vrrp vrid 10 priority 120
- [r2-Ethernet1.10]inter e1.20
- [r2-Ethernet1.20]vrrp vrid 20 virtual-ip 192.168.20.254
查看配置结果:
- interface Ethernet1.10
- vlan-type dot1q vid 10
- ip address 192.168.10.2 255.255.255.0
- vrrp vrid 10 virtual-ip 192.168.10.254
- vrrp vrid 10 priority 120
- !
- interface Ethernet1.20
- vlan-type dot1q vid 20
- ip address 192.168.20.2 255.255.255.0
- vrrp vrid 20 virtual-ip 192.168.20.254
查看vrrp信息:
- [r2] dis vrrp
- Ethernet1.20 | Virtual Router 20
- state : Backup
- Virtual IP : 192.168.20.254
- Priority : 100
- Preempt : YES Delay Time : 0
- Timer : 1
- Auth Type : NO
- Ethernet1.10 | Virtual Router 10
- state : Backup
- Virtual IP : 192.168.10.254
- Priority : 120
- Preempt : YES Delay Time : 0
- Timer : 1
- Auth Type : NO
交换机sw1配置:
- <sw1>sys
- [sw1]inter e0/24
- [sw1-Ethernet0/24]port link-type trunk
- [sw1-Ethernet0/24]port trunk permit vlan all
- [sw1-Ethernet0/24]inter e0/1
- [sw1-Ethernet0/1]port link-type trunk
- [sw1-Ethernet0/1]port trunk permit vlan all
- [sw1-Ethernet0/1]vlan 10
- [sw1-vlan10]port e0/5 to e0/10
- [sw1-vlan10]vlan 20
- [sw1-vlan20]port e0/15 to e0/20
查看配置结果:
- [sw1]dis cu
- interface Ethernet0/5
- port access vlan 10
- #
- interface Ethernet0/6
- port access vlan 10
- #
- interface Ethernet0/7
- port access vlan 10
- #
- interface Ethernet0/8
- port access vlan 10
- #
- interface Ethernet0/9
- port access vlan 10
- #
- interface Ethernet0/10
- port access vlan 10
- #
- interface Ethernet0/11
- #
- interface Ethernet0/12
- #
- interface Ethernet0/13
- #
- interface Ethernet0/14
- #
- interface Ethernet0/15
- port access vlan 20
- #
- interface Ethernet0/16
- port access vlan 20
- #
- interface Ethernet0/17
- port access vlan 20
- #
- interface Ethernet0/18
- port access vlan 20
- #
- interface Ethernet0/19
- port access vlan 20
- #
- interface Ethernet0/20
- port access vlan 20
- #
- interface Ethernet0/21
- #
- interface Ethernet0/22
- #
- interface Ethernet0/23
- #
- interface Ethernet0/24
- port link-type trunk
- port trunk permit vlan all
交换机sw2配置:
- <sw2>sys
- [sw2]inter e0/24
- [sw2-Ethernet0/24]port link-type trunk
- [sw2-Ethernet0/24]port trunk permit vlan all
- [sw2-Ethernet0/24]inter e0/1
- [sw2-Ethernet0/1]port link-type trunk
- [sw2-Ethernet0/1]port trunk permit vlan all
- [sw2-Ethernet0/1]vlan 10
- [sw2-vlan10]port e0/5 to e0/10
- [sw2-vlan10]vlan 20
- [sw2-vlan20]port e0/15 to e0/20
查看配置结果:
- [sw2]dis cu
- interface Ethernet0/5
- port access vlan 10
- #
- interface Ethernet0/6
- port access vlan 10
- #
- interface Ethernet0/7
- port access vlan 10
- #
- interface Ethernet0/8
- port access vlan 10
- #
- interface Ethernet0/9
- port access vlan 10
- #
- interface Ethernet0/10
- port access vlan 10
- #
- interface Ethernet0/11
- #
- interface Ethernet0/12
- #
- interface Ethernet0/13
- #
- interface Ethernet0/14
- #
- interface Ethernet0/15
- port access vlan 20
- #
- interface Ethernet0/16
- port access vlan 20
- #
- interface Ethernet0/17
- port access vlan 20
- #
- interface Ethernet0/18
- port access vlan 20
- #
- interface Ethernet0/19
- port access vlan 20
- #
- interface Ethernet0/20
- port access vlan 20
- #
- interface Ethernet0/21
- #
- interface Ethernet0/22
- #
- interface Ethernet0/23
- #
- interface Ethernet0/24
- port link-type trunk
- port trunk permit vlan all
测试
vlan10内主机跟踪到vlan20跳跃点:
C:\Documents and Settings\Administrator>tracert 192.168.20.101
Tracing route to 192.168.20.101 over a maximum of 30 hops
1
<1 ms <1 ms <1 ms 192.168.10.1
2
1 ms <1 ms <1 ms 192.168.20.101
vlan20内主机跟踪到vlan10跳跃点:
C:\Documents and Settings\Administrator>tracert 192.168.10.101
Tracing route to 192.168.10.101 over a maximum of 30 hops
1
<1 ms <1 ms <1 ms 192.168.20.1
2
1 ms 1 ms <1 ms 192.168.10.101
案例二
实验设备:思科虚拟设备(四台3640路由器、两台虚拟机)
实验拓扑图:
路由器r1配置:
- r1(config)#int f0/0.1
- r1(config-subif)#enca dot1q 10
- r1(config-subif)#ip add 192.168.10.1 255.255.255.0
- r1(config-subif)#int f0/0.2
- r1(config-subif)#enca dot1q 20
- r1(config-subif)#ip add 192.168.20.1 255.255.255.0
- r1(config-subif)#exi
- r1(config)#inter f0/0.1
- r1(config-subif)#standy 10 ip 192.168.10.254
- r1(config-subif)#stan 10 pri 120
- r1(config-subif)#standy 10 preempt //配置优先级权利争夺
- r1(config-subif)#inter f0/0.2
- r1(config-subif)#stand 20 ip 192.168.20.254
- r1(config-subif)#stand 20 pree
- r1(config-subif)#exit
- r1(config)#exit
- interface FastEthernet0/0.1
- encapsulation dot1Q 10
- ip address 192.168.10.1 255.255.255.0
- standby 10 ip 192.168.10.254
- standby 10 priority 120
- standby 10 preempt
- !
- interface FastEthernet0/0.2
- encapsulation dot1Q 20
- ip address 192.168.20.1 255.255.255.0
- standby 20 ip 192.168.20.254
- standby 20 preempt20
查看hsrp信息:
- r1#sh stan bri
- P indicates configured to preempt.
- |
- Interface Grp Prio P State Active Standby Virtual IP
- Fa0/0.1 10 120 P Active local 192.168.10.2 192.168.10.254
- Fa0/0.2 20 100 P Standby 192.168.20.2 local 192.168.20.254
路由器r2配置:
- r2(config)#int f0/0.1
- r2(config-subif)#enca dot1q 10
- r2(config-subif)#ip add 192.168.10.2 255.255.255.0
- r2(config-subif)#int f0/0.2
- r2(config-subif)#enca dot1q 20
- r2(config-subif)#ip add 192.168.20.2 255.255.255.0
- r2(config-subif)#exi
- r2(config)#inter f0/0.1
- r2(config-subif)#stand 10 ip 192.168.10.254
- r2(config-subif)#stand 10 pree
- r2(config-subif)#inter f0/0.2
- r2(config-subif)#stand 20 ip 192.168.20.254
- r2(config-subif)#stan 20 pri 120
- r2(config-subif)#stand 20 pree
- r2(config-subif)#exit
- r2(config)#exit
查看配置结果:
- interface FastEthernet0/0.1
- encapsulation dot1Q 10
- ip address 192.168.10.2 255.255.255.0
- standby 10 ip 192.168.10.254
- standby 10 preempt
- !
- interface FastEthernet0/0.2
- encapsulation dot1Q 20
- ip address 192.168.20.2 255.255.255.0
- standby 20 ip 192.168.20.254
- standby 20 priority 120
- standby 20 preempt
查看hsrp信息:
- r2#sh stan bri
- P indicates configured to preempt.
- |
- Interface Grp Prio P State Active Standby Virtual IP
- Fa0/0.1 10 100 P Standby 192.168.10.1 local 192.168.10.254
- Fa0/0.2 20 120 P Active local 192.168.20.1 192.168.20.254
交换机sw1配置:
- Router(config)#no ip routing
- Router(config)#exit
- sw-1(config)#inter f0/0
- sw-1(config-if)#switc mod trun
- sw-1(config-if)#inter f0/1
- sw-1(config-if)#switc mod trun
- sw-1(config-if)#exit
- sw-1(config)#exit
- sw-1#vlan database //打开vlan数据库
- sw-1(vlan)#vlan 10
- sw-1(vlan)#vlan 20
- sw-1(vlan)#exit
- sw-1(config)#inter rang f0/5 -9
- sw-1(config-if-range)#switch acc vlan 10
- sw-1(config)#inter rang f0/10 -15
- sw-1(config-if-range)#switch acc vlan 20
查看配置结果:
- interface FastEthernet0/0
- switchport mode trunk
- !
- interface FastEthernet0/1
- switchport mode trunk
- !
- interface FastEthernet0/2
- !
- interface FastEthernet0/3
- !
- interface FastEthernet0/4
- !
- interface FastEthernet0/5
- switchport access vlan 10
- !
- interface FastEthernet0/6
- switchport access vlan 10
- !
- interface FastEthernet0/7
- switchport access vlan 10
- !
- interface FastEthernet0/8
- switchport access vlan 10
- !
- interface FastEthernet0/9
- switchport access vlan 10
- !
- interface FastEthernet0/10
- switchport access vlan 20
- !
- interface FastEthernet0/11
- switchport access vlan 20
- !
- interface FastEthernet0/12
- switchport access vlan 20
- !
- interface FastEthernet0/13
- switchport access vlan 20
- !
- interface FastEthernet0/14
- switchport access vlan 20
- !
- interface FastEthernet0/15
- switchport access vlan 20
交换机sw2配置:
- Router(config)#no ip routing
- Router(config)#exit
- sw-2(config)#inter f0/0
- sw-2(config-if)#switc mod trun
- sw-2(config-if)#inter f0/1
- sw-2(config-if)#switc mod trun
- sw-2(config-if)#exit
- sw-2(config)#exit
- sw-2#vlan data
- sw-2(vlan)#vlan 10
- sw-2(vlan)#vlan 20
- sw-2(vlan)#exit
- sw-2(config)#inter rang f0/5 -9
- sw-2(config-if-range)#switch acc vlan 10
- sw-2(config)#inter rang f0/10 -15
- sw-2(config-if-range)#switch acc vlan 20
查看配置结果:
- interface FastEthernet0/0
- switchport mode trunk
- !
- interface FastEthernet0/1
- switchport mode trunk
- !
- interface FastEthernet0/2
- !
- interface FastEthernet0/3
- !
- interface FastEthernet0/4
- !
- interface FastEthernet0/5
- switchport access vlan 10
- !
- interface FastEthernet0/6
- switchport access vlan 10
- !
- interface FastEthernet0/7
- switchport access vlan 10
- !
- interface FastEthernet0/8
- switchport access vlan 10
- !
- interface FastEthernet0/9
- switchport access vlan 10
- !
- interface FastEthernet0/10
- switchport access vlan 20
- !
- interface FastEthernet0/11
- switchport access vlan 20
- !
- interface FastEthernet0/12
- switchport access vlan 20
- !
- interface FastEthernet0/13
- switchport access vlan 20
- !
- interface FastEthernet0/14
- switchport access vlan 20
- !
- interface FastEthernet0/15
- switchport access vlan 20
测试
vlan10内主机跟踪到vlan20跳跃点:
C:\Documents and Settings\Administrator>tracert 192.168.20.20
Tracing route to YANG-KC9WHGH6W9 [192.168.20.20]
over a maximum of 30 hops:
1
109 ms 48 ms 24 ms 192.168.10.1
2
32 ms 9 ms 10 ms YANG-KC9WHGH6W9 [192.168.20.20]
vlan20内主机跟踪到vlan10跳跃点:
C:\Documents and Settings\yang>tracert 192.168.10.10
Tracing route to 192.168.10.10 over a maximum of 30 hops
1
55 ms 12 ms 6 ms 192.168.20.2
2
5 ms 10 ms 6 ms 192.168.10.10
当降低r1的f0/0.10端口的优先级到90时:
vlan10内主机跟踪到vlan20跳跃点:
C:\Documents and Settings\Administrator>tracert 192.168.20.20
Tracing route to YANG-KC9WHGH6W9 [192.168.20.20]
over a maximum of 30 hops:
1
41 ms 16 ms 41 ms 192.168.10.2
2
27 ms 38 ms 9 ms YANG-KC9WHGH6W9 [192.168.20.20]
vlan20内主机跟踪到vlan10跳跃点:
C:\Documents and Settings\yang>tracert 192.168.10.10
Tracing route to 192.168.10.10 over a maximum of 30 hops
1
19 ms 44 ms 7 ms 192.168.20.2
2
9 ms 8 ms 41 ms 192.168.10.10
转载于:https://blog.51cto.com/yz406/967152