VRRP:虚拟路由器冗余协议(VRRP)是一种选择协议,它可以把一个虚拟路由器的责任动态分配到局域网上的 VRRP 路由器中的一台。控制虚拟路由器 IP 地址的 VRRP 路由器称为主路由器,它负责转发数据包到这些虚拟 IP 地址。一旦主路由器不可用,这种选择过程就提供了动态的故障转移机制,这就允许虚拟路由器的 IP 地址可以作为终端主机的默认第一跳路由器。使用 VRRP 的好处是有更高的默认路径的可用性而无需在每个终端主机上配置动态路由或路由发现协议。 VRRP 包封装在 IP 包中发送。
vrrp报文是封装在IP报文上的,支持各种上层协议,同时VRRP还支持将真实接口IP地址设置为虚拟IP地址。
那么如何从备份组的多台交换机中选举Master?这项工作由我们在备份组内每台交换机上配置的相同IP地址的虚拟交换机完成。
虚拟交换机根据配置的优先级的大小选择主交换机,优先级最大的作为主交换机,状态为Master,若优先级相同(如果交换机没有配置优先级,就采用默认值100),则比较接口的主IP地址,主IP地址大的就成为主交换机,由它提供实际的路由服务。其他交换机作为备份交换机,随时监测主交换机的状态。当主交换机正常工作时,它会每隔一段时间发送一个VRRP组播报文,以通知组内的备份交换机,主交换机处于正常工作状态。如果组内的备份交换机长时间没有接收到来自主交换机的VRRP组播报文,则将自己状态转换为Master。当组内有多台备份交换机,将有可能产生多个主交换机。这时每一个主交换机就会比较VRRP报文中的优先级和自己本地的优先级,如果本地的优先级小于VRRP中的优先级,则将自己的状态转换为Backup,否则保持自己的状态不变。通过这样一个过程,就会将优先级最大的交换机选成新的主交换机,完成VRRP的备份功能。
HSRP:热备份路由器协议(HSRP:Hot Standby Router Protocol),是cisco平台一种特有的技术,是cisco的私有协议。
负责转发数据包的路由器称之为活动路由器(Active Router)。一旦主动路由器出现故障,HSRP 将激活备份路由器(Standby Routers)取代主动路由器。HSRP 协议提供了一种决定使用主动路由器还是备份路由器的机制,并指定一个虚拟的 IP 地址作为网络系统的缺省网关地址。如果主动路由器出现故障,备份路由器(Standby Routers)承接主动路由器的所有任务,并且不会导致主机连通中断现象。
HSRP 运行在 UDP 上,采用端口号1985。路由器转发协议数据包的源地址使用的是实际 IP 地址,而并非虚拟地址,正是基于这一点,HSRP 路由器间能相互识别.
HSRP协议利用一个优先级方案来决定哪个配置了HSRP协议的路由器成为默认的主动路由器。如果一个路由器的优先级设置的比所有其他路由器的优先级高,则该路由器成为主动路由器。路由器的缺省优先级是100,所以如果只设置一个路由器的优先级高于100,则该路由器将成为主动路由器。
通过在设置了HSRP协议的路由器之间广播HSRP优先级,HSRP协议选出当前的主动路由器。当在预先设定的一段时间内主动路由器不能发送hello消息时,优先级最高的备用路由器变为主动路由器。路由器之间的包传输对网络上的所有主机来说都是透明的。
案例1:VRRP的应用 (基于H3C设备)
描述:R1在vlan 10区域担任主路由器。
R2在vlan 20区域担任主路由器。
拓扑图:
配置: R1
[R1]dis cu
Now create configuration...
Current configuration
!
version 1.74
local-user user1 service-type administrator password simple 123
sysname R1
firewall enable
aaa-enable
aaa accounting-scheme optional
!
interface Aux0
async mode flow
link-protocol ppp
!
interface Ethernet0
!
interface Ethernet0.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 120
!
interface Ethernet0.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
!
interface Ethernet1
!
interface Serial0
link-protocol ppp
!
interface Serial1
link-protocol ppp
!
interface Async0
R2
[R2]dis cu
Now create configuration...
Current configuration
!
version 1.74
local-user user1 service-type administrator password simple 123
sysname R2
firewall enable
aaa-enable
aaa accounting-scheme optional
!
interface Aux0
async mode flow
link-protocol ppp
!
interface Ethernet0
!
interface Ethernet0.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
!
interface Ethernet0.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 vrid 20 priority 120
!
interface Ethernet1
!
interface Serial0
link-protocol ppp
!
interface Serial1
link-protocol ppp
!
return
S1
[S1]dis cu
#
sysname S1
#
radius scheme system
server-type huawei
primary authentication 127.0.0.1 1645
primary accounting 127.0.0.1 1646
user-name-format without-domain
domain system
radius-scheme system
access-limit disable
state active
vlan-assignment-mode integer
idle-cut disable
self-service-url disable
messenger time disable
domain default enable system
#
local-server nas-ip 127.0.0.1 key huawei
local-user user1
password simple 123
service-type telnet level 3
#
stp enable
#
queue-scheduler wrr 1 2 4 8
#
web set-package force flash:/wnm2.2.2-0001.zip
#
vlan 1
#
vlan 10
#
vlan 20
#
interface Aux0/0
#
interface Ethernet0/1
port link-type trunk
port trunk permit vlan all
#
interface Ethernet0/2
port access vlan 10
#
interface Ethernet0/3
port access vlan 10
#
interface Ethernet0/4
port access vlan 10
#
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
port access vlan 20
#
interface Ethernet0/12
port access vlan 20
#
interface Ethernet0/13
port access vlan 20
#
interface Ethernet0/14
port access vlan 20
#
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
port link-type trunk
port trunk permit vlan all
#
interface Ethernet0/24
#
interface Ethernet0/25
#
interface NULL0
#
user-interface aux 0
user-interface vty 0 4
authentication-mode scheme
#
return
S2
<S2>dis cu
#
sysname S2
#
radius scheme system
server-type huawei
primary authentication 127.0.0.1 1645
primary accounting 127.0.0.1 1646
user-name-format without-domain
domain system
radius-scheme system
access-limit disable
state active
idle-cut disable
self-service-url disable
messenger time disable
domain default enable system
#
local-server nas-ip 127.0.0.1 key huawei
local-user user1
password simple 123
service-type telnet level 3
#
stp enable
#
vlan 1
#
vlan 10
#
vlan 20
# #
interface Vlan-interface2
#
interface Aux0/0
#
interface Ethernet0/1
port link-type trunk
port trunk permit vlan all
#
interface Ethernet0/2
port access vlan 10
#
interface Ethernet0/3
port access vlan 10
#
interface Ethernet0/4
port access vlan 10
#
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
port access vlan 20
#
interface Ethernet0/12
port access vlan 20
#
interface Ethernet0/13
port access vlan 20
#
interface Ethernet0/14
port access vlan 20
#
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
port link-type trunk
port trunk permit vlan all
#
interface Ethernet0/24
#
interface NULL0
#
user-interface aux 0
user-interface vty 0 4
authentication-mode scheme
#
return
测试: R1
[R1]dis vrrp
Ethernet0.10 | Virtual Router 10
state : Master
Virtual IP : 192.168.10.254
Priority : 120
Preempt : YES Delay Time : 0
Timer : 1
Auth Type : NO
Ethernet0.20 | Virtual Router 20
state : Backup
Virtual IP : 192.168.20.254
Priority : 100
Preempt : YES Delay Time : 0
Timer : 1
Auth Type : NO
R2
R2]dis vrrp
Ethernet0.10 | Virtual Router 10
state : Backup
Virtual IP : 192.168.10.254
Priority : 100
Preempt : YES Delay Time : 0
Timer : 1
Auth Type : NO
Ethernet0.20 | Virtual Router 20
state : Master
Virtual IP : 192.168.20.254
Priority : 120
Preempt : YES Delay Time : 0
Timer : 1
Auth Type : NO
PC 10
PC 20
案例2 :HSRP和MSTP的综合应用 (思科设备)
描述:vlan10在Instance 1中。其中S1担任根交换机。R1在vlan 10区域担任主路由器。
vlan 20在Instance 2中。其中S2担任根交换机。R2在vlan 20区域担任主路由器
拓扑图
r1配置
interface Ethernet1.10
vlan-type dot1q vid 10 //封装为dot1q
ip address 192.168.10.1 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 //封装为dot1q
ip address 192.168.20.1 255.255.255.0 // 配置ip
vrrp vrid 20 virtual-ip 192.168.20.254 //配置虚拟ip
r2配置
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
interface Ethernet1.20
vlan-type dot1q vid 20 //封装为dot1q
ip address 192.168.20.2 255.255.255.0
vrrp vrid 20 virtual-ip 192.168.20.254
vrrp vrid 20 priority 120 //设置优先级
sw-1配置
vlan 10
port e0/5 to e0/10 //创建vlan10
vlan 20 //创建vlan20
port e0/15 to e0/20
interface Ethernet0/1
port link-type trunk
port trunk permit vlan all
interface Ethernet0/5
port access vlan 10
interface Ethernet0/24
port link-type trunk //trunk模式
port trunk permit vlan all //允许所有vlan通过
sw-2配置
vlan 10
port e0/5 to e0/10 //创建vlan10
vlan 20 //创建vlan20
port e0/15 to e0/20
interface Ethernet0/1
port link-type trunk
port trunk permit vlan all
interface Ethernet0/24
port link-type trunk
port trunk permit vlan all
转载于:https://blog.51cto.com/jinjianping/965912