1.组网需求
如下图,HostA
和 HostC
通过 Switch
双归属到 RouterA
和 RouterB
。现要求:
HostA
以RouterA
为默认网关接入Internet
,RouterB
作为备份网关HostC
以RouterB
为默认网关接入Internet
,RouterA
作为备份网关
从而实现流量的负载均衡。
2.配置思路
如下图,采用 VRRP
多网关负载分担实现流量的负载均衡:
1)配置各设备接口 IP
地址及路由协议,使各设备间网络层连通。
2)在 RouterA
和 RouterB
上创建 VRRP
备份组1 和 VRRP
备份组2,在备份组1中,配置 RouterA
为Master
设备,RouterB
为 Backup
设备;在备份组2中,配置 RouterB
为 Master
设备,RouterA
为 Backup
设备,实现流量的负载均衡。
3.配置步骤
3.1配置设备间的网络互连
# 配置设备各接口的IP
地址
路由器 RouterA
:
[Huawei]sysname RouterA
[RouterA]interface GigabitEthernet 1/0/0
[RouterA-GigabitEthernet1/0/0]ip address 192.168.1.1 24
[RouterA-GigabitEthernet1/0/0]quit
[RouterA]interface GigabitEthernet 2/0/0
[RouterA-GigabitEthernet2/0/0]ip address 10.1.1.1 24
[RouterA-GigabitEthernet2/0/0]quit
[RouterA]
路由器 RouterB
:
[Huawei]sysname RouterB
[RouterB]interface GigabitEthernet 1/0/0
[RouterB-GigabitEthernet1/0/0]ip address 192.168.2.1 24
[RouterB-GigabitEthernet1/0/0]quit
[RouterB]interface GigabitEthernet 2/0/0
[RouterB-GigabitEthernet2/0/0]ip address 10.1.1.2 24
[RouterB-GigabitEthernet2/0/0]quit
[RouterB]
路由器 RouterC
:
[Huawei]sysname RouterC
[RouterC]interface GigabitEthernet 1/0/0
[RouterC-GigabitEthernet1/0/0]ip address 192.168.1.2 24
[RouterC-GigabitEthernet1/0/0]quit
[RouterC]interface GigabitEthernet 2/0/0
[RouterC-GigabitEthernet2/0/0]ip address 192.168.2.2 24
[RouterC-GigabitEthernet2/0/0]quit
[RouterC]interface GigabitEthernet 3/0/0
[RouterC-GigabitEthernet3/0/0]ip address 172.16.1.3 24
[RouterC-GigabitEthernet3/0/0]quit
[RouterC]
# 配置 RouterA、RouterB
和 RouterC
间采用 OSPF
协议进行互连
路由器 RouterA
:
[RouterA]ospf 1
[RouterA-ospf-1]area 0
[RouterA-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.255
[RouterA-ospf-1-area-0.0.0.0]network 10.1.1.0 0.0.0.255
[RouterA-ospf-1-area-0.0.0.0]quit
[RouterA-ospf-1]quit
[RouterA]
路由器 RouterB
:
[RouterB]ospf 1
[RouterB-ospf-1]area 0
[RouterB-ospf-1-area-0.0.0.0]network 192.168.2.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0]network 10.1.1.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0]quit
[RouterB-ospf-1]quit
[RouterB]
路由器 RouterC
:
[RouterC]ospf 1
[RouterC-ospf-1]area 0
[RouterC-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.255
[RouterC-ospf-1-area-0.0.0.0]network 192.168.2.0 0.0.0.255
[RouterC-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.255
[RouterC-ospf-1-area-0.0.0.0]quit
[RouterC-ospf-1]quit
[RouterC]
配置 ospf
完成后,可以查看邻居建立情况:
路由器 RouterA
:
[RouterA]display ospf peer
OSPF Process 1 with Router ID 192.168.1.1
Neighbors
Area 0.0.0.0 interface 192.168.1.1(GigabitEthernet1/0/0)'s neighbors
Router ID: 192.168.1.2 Address: 192.168.1.2
State: Full Mode:Nbr is Master Priority: 1
DR: 192.168.1.2 BDR: 192.168.1.1 MTU: 0
Dead timer due in 33 sec
Retrans timer interval: 5
Neighbor is up for 00:02:54
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 10.1.1.1(GigabitEthernet2/0/0)'s neighbors
Router ID: 192.168.2.1 Address: 10.1.1.2
State: Full Mode:Nbr is Master Priority: 1
DR: 10.1.1.1 BDR: 10.1.1.2 MTU: 0
Dead timer due in 38 sec
Retrans timer interval: 5
Neighbor is up for 00:01:41
Authentication Sequence: [ 0 ]
[RouterA]
路由器 RouterB
:
[RouterB]dis ospf peer
OSPF Process 1 with Router ID 192.168.2.1
Neighbors
Area 0.0.0.0 interface 192.168.2.1(GigabitEthernet1/0/0)'s neighbors
Router ID: 192.168.1.2 Address: 192.168.2.2
State: Full Mode:Nbr is Slave Priority: 1
DR: 192.168.2.2 BDR: 192.168.2.1 MTU: 0
Dead timer due in 40 sec
Retrans timer interval: 5
Neighbor is up for 00:03:13
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 10.1.1.2(GigabitEthernet2/0/0)'s neighbors
Router ID: 192.168.1.1 Address: 10.1.1.1
State: Full Mode:Nbr is Slave Priority: 1
DR: 10.1.1.1 BDR: 10.1.1.2 MTU: 0
Dead timer due in 29 sec
Retrans timer interval: 0
Neighbor is up for 00:02:55
Authentication Sequence: [ 0 ]
[RouterB]
路由器 RouterC
:
[RouterC]dis ospf peer
OSPF Process 1 with Router ID 192.168.1.2
Neighbors
Area 0.0.0.0 interface 192.168.1.2(GigabitEthernet1/0/0)'s neighbors
Router ID: 192.168.1.1 Address: 192.168.1.1
State: Full Mode:Nbr is Slave Priority: 1
DR: 192.168.1.2 BDR: 192.168.1.1 MTU: 0
Dead timer due in 40 sec
Retrans timer interval: 5
Neighbor is up for 00:04:49
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 192.168.2.2(GigabitEthernet2/0/0)'s neighbors
Router ID: 192.168.2.1 Address: 192.168.2.1
State: Full Mode:Nbr is Master Priority: 1
DR: 192.168.2.2 BDR: 192.168.2.1 MTU: 0
Dead timer due in 31 sec
Retrans timer interval: 5
Neighbor is up for 00:03:54
Authentication Sequence: [ 0 ]
[RouterC]
3.2配置VRRP备份组
3.2.1配置VRRP备份组1
# 在 RouterA 和 RouterB 上创建 VRRP 备份组1,配置 RouterA 的优先级为 120,抢占延时为 20 秒;RouterB 的优先级为缺省值。
[RouterA]interface GigabitEthernet 2/0/0
[RouterA-GigabitEthernet2/0/0]vrrp vrid 1 virtual-ip 10.1.1.100
[RouterA-GigabitEthernet2/0/0]vrrp vrid 1 priority 120
[RouterA-GigabitEthernet2/0/0]vrrp vrid 1 preempt-mode timer delay 20
[RouterA-GigabitEthernet2/0/0]quit
[RouterA]
[RouterB]interface GigabitEthernet 2/0/0
[RouterB-GigabitEthernet2/0/0]vrrp vrid 1 virtual-ip 10.1.1.100
[RouterB-GigabitEthernet2/0/0]quit
[RouterB]
3.2.2配置VRRP备份组2
# 在 RouterA 和 RouterB 上创建 VRRP 备份组2,配置 RouterB 的优先级为 120,抢占延时为 20 秒;RouterA 的优先级为缺省值。
[RouterB]interface GigabitEthernet 2/0/0
[RouterB-GigabitEthernet2/0/0]vrrp vrid 2 virtual-ip 10.1.1.101
[RouterB-GigabitEthernet2/0/0]vrrp vrid 2 priority 120
[RouterB-GigabitEthernet2/0/0]vrrp vrid 2 preempt-mode timer delay 20
[RouterB-GigabitEthernet2/0/0]quit
[RouterB]
[RouterA]interface GigabitEthernet 2/0/0
[RouterA-GigabitEthernet2/0/0]vrrp vrid 2 virtual-ip 10.1.1.101
[RouterA-GigabitEthernet2/0/0]quit
[RouterA]
4.验证配置
# 在 RouterA 上执行 display vrrp 命令,可以看到 RouterA 在备份组1中作为 Master 设备,在备份组2中作为 Backup设备。
[RouterA]display vrrp
GigabitEthernet2/0/0 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.100
Master IP : 10.1.1.1
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 20 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Backup-forward : disabled
Create time : 2025-01-07 18:39:36 UTC-08:00
Last change time : 2025-01-07 18:39:39 UTC-08:00
GigabitEthernet2/0/0 | Virtual Router 2
State : Backup
Virtual IP : 10.1.1.101
Master IP : 10.1.1.2
PriorityRun : 100
PriorityConfig : 100
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
Backup-forward : disabled
Create time : 2025-01-07 18:45:49 UTC-08:00
Last change time : 2025-01-07 18:45:49 UTC-08:00
[RouterA]
# 在 RouterB 上执行 display vrrp 命令,可以看到 RouterB 在备份组1中作为 Backup 设备,在备份组2中作为 Master 设备。
[RouterB]display vrrp
GigabitEthernet2/0/0 | Virtual Router 1
State : Backup
Virtual IP : 10.1.1.100
Master IP : 10.1.1.1
PriorityRun : 100
PriorityConfig : 100
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
Backup-forward : disabled
Create time : 2025-01-07 18:42:05 UTC-08:00
Last change time : 2025-01-07 18:42:05 UTC-08:00
GigabitEthernet2/0/0 | Virtual Router 2
State : Master
Virtual IP : 10.1.1.101
Master IP : 10.1.1.2
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 20 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0102
Check TTL : YES
Config type : normal-vrrp
Backup-forward : disabled
Create time : 2025-01-07 18:44:22 UTC-08:00
Last change time : 2025-01-07 18:44:25 UTC-08:00
[RouterB]