通常情况下,在终端设备进入网络前,都会有一个 Router 充当网络,作为第一跳的网络地址。但假设路由器发生故障,此时终端设备就无法再接入互联网。
为了防止这样的问题,一般会再加入一台路由器充当备份。但此时就出现一个问题,网关地址配这两个路由器中的那个?
于是 FHRP 协议出现,可以将多个路由器虚拟成一个路由器提供服务,当提供服务的路由器发生故障时,会自动切换到另一台上。
FHRP 是这类路由协议的统称,常见路由协议如下:
HRSP 热备份冗余协议,是 CISCO 私有协议,用于解决网关的备份问题。
能够在不改变组网的情况下,将多台路由器虚拟成一个虚拟路由器。
HRSP 组:由多个 HRSP 路由器组成,属于同一个 HSRP 组,组内的路由器会交换信息,每个组由唯一 ID 指定。经过选举会推选出 Active 路由器和 Standby 路由器。
HSRP 虚拟路由:对每个 HSRP 组,抽象出的虚拟路由器。作为我拿过来。具有虚拟 IP 和 MAC。虚拟出来的 IP 作为网关地址。
Active 路由器:HSRP 中实际转发数据包的路由器,每个 HRSP 组中,仅有一个 active 路由器,并绑定虚拟 IP,用于响应请求。
Stand by 路由器:在 HSRP 组中,处于监听状态的路由器,当 Active 路由器出现问题时,接替工作。
HSRPV1 | HSRPV2 |
---|---|
IPv4 | HSRPv4/v6 |
Group numbers 0 - 255 | Group numbers 0 -4095 |
Virtual MAC: 0000:0C07:ACxx (xx 来源 HSRP 组) | Virtual MAC: 0000:0C9F:Fxxx (xxx 来源 HSRP 组) |
广播地址:224.0.0.2 | 广播地址:224.0.0.102 |
将 R1 和 R2 配置 HRSP 协议,down 掉 R1,网络依然正常。
# R1
inter Eth0/0
standby 1 ip 192.168.1.254
standby 1 priority 120
show standby
# R2
inter Eth0/0
standby 1 192.168.1.254
standby 1 priority 100
准备工作 1 - 4:
# PC 5: IP 网关
VPC5> ip 10.1.1.1/24 10.1.1.251
# PC 6:
VPC6> ip 20.1.1.1/24 20.1.1.252
# SW3:
vlan 10,20
!
hostname SW3
!
interface Ethernet0/0
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface Ethernet0/1
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface Ethernet0/2
switchport access vlan 10
switchport mode access
!
interface Ethernet0/3
switchport access vlan 20
switchport mode access
!
# SW1
vlan 10,20
ip routing
!
hostname SW1
!
interface Ethernet0/0
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface Ethernet0/1
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface Ethernet0/2
no switchport
ip address 100.1.1.1 255.255.255.0
!
interface Vlan10
ip address 10.1.1.251 255.255.255.0
!
interface Vlan20
ip address 20.1.1.251 255.255.255.0
!
router eigrp 1
network 100.1.1.0 0.0.0.255
network 10.1.1.251 0.0.0.255
network 20.1.1.251 0.0.0.255
!
# SW2
vlan 10,20
ip routing
!
hostname SW2
!
interface Ethernet0/0
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface Ethernet0/1
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface Ethernet0/2
no switchport
ip address 200.1.1.1 255.255.255.0
!
interface Vlan10
ip address 10.1.1.252 255.255.255.0
!
interface Vlan20
ip address 20.1.1.252 255.255.255.0
!
!
router eigrp 1
network 200.1.1.0 0.0.0.255
network 10.1.1.252 0.0.0.255
network 20.1.1.252 0.0.0.255
!
# Router
!
hostname R1
!
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Ethernet0/0
ip address 100.1.1.2 255.255.255.0
duplex auto
!
interface Ethernet0/1
ip address 200.1.1.2 255.255.255.0
duplex auto
!
router eigrp 1
network 1.1.1.1 0.0.0.0
network 100.1.1.0 0.0.0.255
network 200.1.1.0
!
配置成功后,PC 5 可以 ping 通 PC6.
并且可以在 SW1 或 2 看到如下的路由信息:
SW2#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
D 1.1.1.0 [90/409600] via 200.1.1.2, 00:31:52, Ethernet0/2
10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 10.1.1.0/24 is directly connected, Vlan10
L 10.1.1.252/32 is directly connected, Vlan10
20.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 20.1.1.0/24 is directly connected, Vlan20
L 20.1.1.252/32 is directly connected, Vlan20
100.0.0.0/24 is subnetted, 1 subnets
D 100.1.1.0 [90/307200] via 200.1.1.2, 00:31:52, Ethernet0/2
200.1.1.0/24 is variably subnetted, 2 subnets, 2 masks
C 200.1.1.0/24 is directly connected, Ethernet0/2
L 200.1.1.1/32 is directly connected, Ethernet0/2
配置 SW1 为 VLAN 10 的根桥 ID. 配置 SW2 为 VLAN 20 的根桥 ID.
# SW1
SW1(config)#spanning-tree vlan 10 priority 0
SW1(config)#spanning-tree vlan 20 priority 4096
# SW2
SW2(config)#spanning-tree vlan 10 priority 4096
SW2(config)#spanning-tree vlan 20 priority 0
现在用 PC5 Ping 1.1.1.1:
trace to 1.1.1.1, 8 hops max, press Ctrl+C to stop
1 10.1.1.251 0.893 ms 0.852 ms 2.083 ms
2 *100.1.1.2 0.654 ms (ICMP type:3, code:3, Destination port unreachable) *
用 PC6 Ping 1.1.1.1:
VPC6> trace 1.1.1.1
trace to 1.1.1.1, 8 hops max, press Ctrl+C to stop
1 20.1.1.252 0.402 ms 0.327 ms 0.378 ms
2 *200.1.1.2 0.754 ms (ICMP type:3, code:3, Destination port unreachable) *
可以发现 VLAN 10 走 SW1 ,VLAN 20 走 SW2.
配置 HSRP :
# 配置 Vlan 10 HSRP:
SW1(config)#int vlan 10
SW1(config)#standby 1 ip 10.1.1.254
SW1(config)#standby 1 priority 120
SW2(config)#int vlan 10
SW2(config)#standby 1 ip 10.1.1.254
SW2(config)#standby 1 priority 100
# 配置 Vlan 20 HSRP:
SW1(config)#int vlan 20
SW1(config)#standby 2 ip 20.1.1.254
SW1(config)#standby 2 priority 100
SW2(config)#int vlan 20
SW2(config)#standby 2 ip 20.1.1.254
SW2(config)#standby 2 priority 120
此时将 PC5 和 PC 6 的网关改为:10.1.1.254 和 20.1.1.254. 然后 shutdown SW1 vlan 10,可以发现依然可以访问 1.1.1.1 只不过现在走 SW2. 这条备份链路。
接着将 Vlan1 10 接口打开, 但发现无法将 VLAN 10 的 Active 恢复 SW1,这时需要打开抢占功能:
SW1(config)#interface Vlan 10
SW1(config-if)#standby 1 preempt
打开认证功能:
SW2(config)#int vlan 10
SW2(config-if)#standby 1 authentication md5 key-string cisco
SW1(config)#int vlan 10
SW1(config-if)#standby 1 authentication md5 key-string cisco
打开链路跟踪功能, 当 SW1 或 SW2 上行链路出现问题,立即进行切换:
SW1(config)# track 1 inerface e0/2 line-protocol
SW1(config)#int vlan 10
# 调用跟踪链路 track1
SW1(config-if)#standby 2 track 1 decrement 30
# 抢占等待时间 10
SW2(config-if)#standby 2 preempt delay minimum 10
SW2(config)# track 1 inerface e0/2 line-protocol
SW2(config)#int vlan 20
SW2(config-if)#standby 2 track 1 decrement 30
SW2(config-if)#standby 2 preempt delay minimum 10
VRRP 本身是公有协议,和 HSRP 非常类似,用于解决网关备份的问题。
VRRP 组:由多个 VRRP 路由器组成,属于同一个 VRRP 组,组内的路由器会交换信息,每个组由唯一 ID 指定。经过选举会推选出 Active 路由器和 Standby 路由器。
VRRP 虚拟路由:对每个 HSRP 组,抽象出的虚拟路由器。作为我拿过来。具有虚拟 IP 和 MAC。虚拟出来的 IP 作为网关地址。
Master 路由器:HSRP 中实际转发数据包的路由器,每个 HRSP 组中,仅有一个 Master 路由器,并绑定虚拟 IP,用于响应请求。
backup 路由器:在 HSRP 组中,处于监听状态的路由器,当 Master 路由器出现问题时,接替工作。
GLBP 思科私有协议,和 VRRP 不同,组内可有多台 Active,能实现真正意义的上的负载分担。能提供一个虚拟 IP 和多个 MAC 地址并分配给 PC。
当 PC 在解析网关时,由于一个 IP 对应多个 MAC 地址,可将流量分配到不同的 MAC 地址所对应的设备上,实现负载分摊。
通过 Hello 报文交互,数值越大,优先级越高。如果优先级一样,选 IP 地址大的。
负载分摊模式:
# R1
inter Eth0/0
glbp 1 ip 192.168.1.254
show glbp
需要注意的是 GLBP 不能用在二层链路上,因为二层链路上存在生成树协议,存在阻塞端口,进一步导致次优路径。
本篇共提到了三个协议,用于解决网关单点故障的问题。
从目前使用的情况看,VRRP 由于是公有协议使用的更多些。HSRP 和 GLBP 由于是思科的私有协议,仅能跑在思科设备上。
从配置的角度看,VRRP 和 HSRP 非常类似,其中概念也较为相似。仅在命名和选举的计算方式稍有不同。
从流量的负载角度看,GLBP 更加优秀一些,相比 VRRP 和 HSRP,实现的是真正意义上的负载分摊。但由于其存在多个 MAC 的原因,不能适用于充当二层网关的设备。