eNSP 防火墙双机热备(主备)与 VRRP 网关冗余实验
实验平台:华为 eNSP + USG6000V 防火墙
实验目标:两台防火墙组成主备(Active/Standby)双机热备系统,对内网 PC 提供永不中断的虚拟网关,主设备故障时业务自动切换到备设备。
适用读者:正在学习 HCIA/HCIP Security、防火墙双机热备或 VRRP 的同学,可直接按本文拓扑与命令复现实验。
一、实验拓扑
1.1 拓扑图

text
Cloud1
Eth0/0/2 Eth0/0/3
| |
GE0/0/0 GE0/0/0 (管理网,接宿主机网卡)
| |
┌────┴───┐ ┌───┴────┐
│ FW1 │ │ FW2 │
└───┬────┘ └───┬────┘
GE1/0/6 ──────────┘ └────────── GE1/0/6
(心跳线直连,HRP 同步会话表 / 协商 VGMP 状态)
\ /
GE1/0/5 \ / GE1/0/5
\ /
GE0/0/3 GE0/0/2
┌──────────┐
│ LSW1 │
└────┬─────┘
GE0/0/1
|
Eth0/0/1
┌────────┐
│ PC1 │
└────────┘
1.2 接口连接关系
| 本端设备 | 本端接口 | 对端设备 | 对端接口 | 用途 |
|---|---|---|---|---|
| Cloud1 | Ethernet 0/0/2 | FW1 | GE 0/0/0 | 管理网,Web/SSH 登录防火墙 |
| Cloud1 | Ethernet 0/0/3 | FW2 | GE 0/0/0 | 管理网,Web/SSH 登录防火墙 |
| FW1 | GE 1/0/6 | FW2 | GE 1/0/6 | 心跳直连(HRP) |
| FW1 | GE 1/0/5 | LSW1 | GE 0/0/3 | 业务下行口(Trust) |
| FW2 | GE 1/0/5 | LSW1 | GE 0/0/2 | 业务下行口(Trust) |
| LSW1 | GE 0/0/1 | PC1 | Ethernet 0/0/1 | 终端接入(二层透传) |
说明:LSW1 为二层交换机,三个接口均处于 VLAN 1,无需任何配置即可转发。FW1 与 FW2 的 GE1/0/5 必须处在同一个二层广播域,VRRP 通告才能互通。
1.3 IP 地址规划
| 设备 / 接口 | IP 地址 | 说明 |
|---|---|---|
| FW1 GE0/0/0 | 192.168.100.1/24 | 管理口,接 Cloud1 |
| FW2 GE0/0/0 | 192.168.100.2/24 | 管理口,接 Cloud1 |
| FW1 GE1/0/6 | 10.0.0.1/30 | 心跳口 |
| FW2 GE1/0/6 | 10.0.0.2/30 | 心跳口 |
| FW1 GE1/0/5 | 192.168.1.251/24 | 业务口,Trust 区域 |
| FW2 GE1/0/5 | 192.168.1.252/24 | 业务口,Trust 区域 |
| VRRP 备份组 1 | 192.168.1.254/24 | PC1 的默认网关 |
| PC1 | 192.168.1.10/24 | 网关填写 192.168.1.254 |
| 宿主机(可选) | 192.168.100.10/24 | Cloud1 绑定的真实网卡,模拟外网 |
二、实验原理简述
2.1 VRRP
VRRP(Virtual Router Redundancy Protocol,虚拟路由冗余协议)把多台三层设备虚拟成一台"虚拟路由器",对内网的网关就是虚拟 IP(VIP)。正常情况下由 Master 设备响应 ARP 并转发流量;Master 故障时,Backup 设备接替工作,终端无需修改任何配置。
2.2 VGMP:为什么防火墙不用 priority 120/100
在路由器上配置 VRRP 一般用 priority 120 / 100 + preempt-mode;但在华为防火墙上,双机热备使用 VGMP(VRRP Group Management Protocol) 统一管理所有 VRRP 备份组的状态:
- VGMP 组默认优先级 45000,状态分为 Active 与 Standby;
- 设备角色由 VGMP 组决定,不再由 VRRP 报文独立选举;
- 任一下行业务接口故障,VGMP 优先级自动减 2,触发整组切换,避免出现"上行走 FW1、下行走 FW2"的流量黑洞;
- 因此防火墙上 VRRP 的配置关键字是
active/standby,而不是priority。
在防火墙上执行
display vrrp brief仍能看到 Priority 字段(默认 100),这是 VRRP 本身的属性,不代表主备选举依据。
2.3 HRP
HRP(Huawei Redundancy Protocol)负责两台防火墙之间的配置同步 和会话表 / Server-map 表同步 。心跳线既承载 VGMP 状态协商,也承载会话备份。本实验心跳口使用 remote 参数(单播 UDP 封装),因此必须放行 local → dmz 的安全策略。
三、实验配置步骤
步骤 1:终端与 Cloud 基础配置
- PC1 的 IP 配置为
192.168.1.10/24,网关192.168.1.254。 - Cloud1 绑定宿主机上的一块真实网卡(例如 VMware VMnet1),宿主机网卡配置
192.168.100.10/24。 - 在 eNSP 中按拓扑连线并启动所有设备。USG6000V 首次启动较慢,出现
####时耐心等待即可。
步骤 2:FW1 基础配置(接口 IP + 安全区域)
bash
system-view
sysname FW1
undo info-center enable
#
interface GigabitEthernet0/0/0
ip address 192.168.100.1 255.255.255.0
service-manage all permit
#
interface GigabitEthernet1/0/5
ip address 192.168.1.251 255.255.255.0
service-manage ping permit
#
interface GigabitEthernet1/0/6
ip address 10.0.0.1 255.255.255.252
#
firewall zone trust
add interface GigabitEthernet1/0/5
#
firewall zone untrust
add interface GigabitEthernet0/0/0
#
firewall zone dmz
add interface GigabitEthernet1/0/6
#
security-policy
rule name permit_heartbeat
source-zone local
destination-zone dmz
action permit
permit_heartbeat必须提前配置,否则带remote参数的心跳报文(local → dmz 单播)会被丢弃,主备无法协商。
步骤 3:FW2 基础配置(接口 IP + 安全区域)
bash
system-view
sysname FW2
undo info-center enable
#
interface GigabitEthernet0/0/0
ip address 192.168.100.2 255.255.255.0
service-manage all permit
#
interface GigabitEthernet1/0/5
ip address 192.168.1.252 255.255.255.0
service-manage ping permit
#
interface GigabitEthernet1/0/6
ip address 10.0.0.2 255.255.255.252
#
firewall zone trust
add interface GigabitEthernet1/0/5
#
firewall zone untrust
add interface GigabitEthernet0/0/0
#
firewall zone dmz
add interface GigabitEthernet1/0/6
#
security-policy
rule name permit_heartbeat
source-zone local
destination-zone dmz
action permit
心跳口两端接口编号必须一致(本例都是 GE1/0/6),且加入同一个安全区域(DMZ)。
步骤 4:创建 VRRP 备份组
FW1(初始角色 Active):
bash
interface GigabitEthernet1/0/5
vrrp vrid 1 virtual-ip 192.168.1.254 active
FW2(初始角色 Standby):
bash
interface GigabitEthernet1/0/5
vrrp vrid 1 virtual-ip 192.168.1.254 standby
若你的设备版本提示命令不完整,可写成
vrrp vrid 1 virtual-ip 192.168.1.254 24 active。虚拟 IP 不能与任何设备的物理接口 IP 相同。
步骤 5:配置 HRP 双机热备
FW1:
bash
hrp interface GigabitEthernet1/0/6 remote 10.0.0.2
hrp enable
hrp mirror session enable
hrp auto-sync
FW2:
bash
hrp interface GigabitEthernet1/0/6 remote 10.0.0.1
hrp enable
hrp mirror session enable
hrp auto-sync
配置完成后,命令行提示符会发生变化:主设备变为 HRP_M[FW1],备设备变为 HRP_S[FW2]。
hrp mirror session enable:开启会话快速备份,保证切换时已有连接不中断;hrp auto-sync:配置自动同步(默认开启),在主设备上敲的命令会自动同步到备机;- 备机处于 Standby 时大部分配置命令会被拒绝,业务策略只能在主设备上配置。
步骤 6:在主设备上配置业务安全策略
在 FW1 上配置,观察命令末尾出现 (+B) 提示,说明已同步到 FW2:
bash
HRP_M[FW1] security-policy
HRP_M[FW1-policy-security] rule name trust_to_untrust
HRP_M[FW1-policy-security-rule-trust_to_untrust] source-zone trust
HRP_M[FW1-policy-security-rule-trust_to_untrust] destination-zone untrust
HRP_M[FW1-policy-security-rule-trust_to_untrust] source-address 192.168.1.0 mask 255.255.255.0
HRP_M[FW1-policy-security-rule-trust_to_untrust] action permit
在 FW2 上验证策略已同步(备机不能进入 security-policy 视图,用 display current-configuration 查看):
bash
HRP_S[FW2] display current-configuration | include rule
四、实验验证
4.1 查看 VRRP 状态
bash
display vrrp brief
FW1 输出示例:
text
Interface VRID Virtual IP State Priority Preempt
GigabitEthernet1/0/5 1 192.168.1.254 Master 100 Yes
FW2 输出示例:
text
Interface VRID Virtual IP State Priority Preempt
GigabitEthernet1/0/5 1 192.168.1.254 Backup 100 Yes
4.2 查看 HRP 状态与心跳口
bash
display hrp state
display hrp interface
正常输出应类似:
text
Role: active, peer: standby
Running priority: 45000, peer: 45000
...
GigabitEthernet1/0/6 : running
4.3 业务连通性测试
在 PC1 上持续 ping 虚拟网关:
text
ping 192.168.1.254 -t
结果:全部通,TTL 正常。在 FW1 上查看会话表,并对比 FW2 上的备份会话:
bash
display firewall session table
FW2 上会看到带 Remote 标记的会话条目,说明会话同步成功:
text
icmp VPN: public --> public Remote 192.168.1.10:xxxx --> 192.168.1.254:xxxx
4.4 管理口测试(可选)
宿主机浏览器访问 https://192.168.100.1 和 https://192.168.100.2,均可登录对应防火墙(首次需修改默认密码)。
五、故障切换实验
保持 PC1 持续 ping 192.168.1.254 -t,然后模拟故障。
场景一:主设备业务接口故障
在 FW1 上关闭下行业务口:
bash
HRP_M[FW1] interface GigabitEthernet1/0/5
HRP_M[FW1-GigabitEthernet1/0/5] shutdown
观察现象:
- PC1 只丢 1~2 个包,随后恢复通信;
- FW2 提示符变为
HRP_M[FW2],display vrrp brief显示 State 为 Master; display hrp state中两端角色互换,FW1 侧 Running priority 降低(44998 < 45000);- 恢复命令:
undo shutdown,FW1 会重新抢占回 Active。
shutdown命令不会被同步到备机(命令后没有(+B)),因此不会影响 FW2 的正常接口。
场景二:主设备整机故障
直接关闭 FW1 电源或重启 FW1,切换效果与场景一相同,PC1 感知到的中断时间约为秒级。
场景三:心跳线故障(思考题)
断开 GE1/0/6 心跳线后,两台防火墙均认为自己是 Active,产生"双主"现象,业务会时通时断。生产环境中通常通过多条心跳线 + BFD 检测来规避,本实验可自行拔线观察现象。
六、扩展实验:在 GE1/0/5 下用子接口创建多个网关
当一个物理口后面挂着多个网段(例如 VLAN 10、VLAN 20)都需要网关冗余时,不需要为每个网段占用一个物理接口。可以在 GE1/0/5 下创建逻辑子接口,每个子接口终结一个 VLAN、配置一个 IP 并加入一个 VRRP 备份组。这是华为防火墙"单臂多网关"的标准做法。
6.1 扩展需求与规划
在原有实验基础上,清除 GE1/0/5 主接口上的 IP 与 VRRP 组,改为两个子接口:
| 子接口 | 终结 VLAN | FW1 IP | FW2 IP | VRRP 备份组 | 虚拟网关 |
|---|---|---|---|---|---|
| GE1/0/5.10 | 10 | 192.168.10.251/24 | 192.168.10.252/24 | vrid 10 | 192.168.10.254 |
| GE1/0/5.20 | 20 | 192.168.20.251/24 | 192.168.20.252/24 | vrid 20 | 192.168.20.254 |
6.2 清除原主接口配置(FW1、FW2 都要做)
bash
interface GigabitEthernet1/0/5
undo ip address
undo vrrp vrid 1
6.3 配置子接口(FW1)
bash
interface GigabitEthernet1/0/5.10
dot1q termination vid 10
ip address 192.168.10.251 255.255.255.0
vrrp vrid 10 virtual-ip 192.168.10.254 active
service-manage ping permit
#
interface GigabitEthernet1/0/5.20
dot1q termination vid 20
ip address 192.168.20.251 255.255.255.0
vrrp vrid 20 virtual-ip 192.168.20.254 active
service-manage ping permit
#
firewall zone trust
add interface GigabitEthernet1/0/5.10
add interface GigabitEthernet1/0/5.20
配置子接口(FW2)------IP 改为 .252,VRRP 关键字改为 standby:
bash
interface GigabitEthernet1/0/5.10
dot1q termination vid 10
ip address 192.168.10.252 255.255.255.0
vrrp vrid 10 virtual-ip 192.168.10.254 standby
service-manage ping permit
#
interface GigabitEthernet1/0/5.20
dot1q termination vid 20
ip address 192.168.20.252 255.255.255.0
vrrp vrid 20 virtual-ip 192.168.20.254 standby
service-manage ping permit
#
firewall zone trust
add interface GigabitEthernet1/0/5.10
add interface GigabitEthernet1/0/5.20
6.4 LSW1 侧改为 Trunk
bash
vlan batch 10 20
#
interface GigabitEthernet0/0/3
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 10
6.5 几个关键点
- 所有 VRRP 备份组默认加入同一个 VGMP 组。因此 vrid 10 与 vrid 20 会随主备状态一起切换,不会出现"VLAN 10 的网关在 FW1、VLAN 20 的网关在 FW2"的分裂现象------这正是防火墙多网关场景想要的。
- 子接口要单独加入安全区域 。只把主接口 GE1/0/5 加入 trust 不够,GE1/0/5.10 和 GE1/0/5.20 都要
add interface。 - VRRP 报文的 VLAN Tag :eNSP 的 USG6000V 通常只需
dot1q termination vid即可正常跑 VRRP。若你的版本 VRRP 通告不通,在子接口下补dot1q vrrp 10(各子接口填自己的 vid)和arp broadcast enable。 - 不要把虚拟 IP 配成静态 ARP 的映射地址,否则会生成错误主机路由,导致转发异常。
- 若业务要求"不同网段分别由不同防火墙做主"(负载分担),需要拆分 VGMP 组并让两台设备互为主备,属于进阶场景,本文不展开。
- 验证:
display vrrp brief应能看到两个备份组;PC1(VLAN 10)持续 ping 192.168.10.254,关闭 FW1 的 GE1/0/5.10 后,两个 VIP 应同时切到 FW2。
七、常见坑与排错清单
| 现象 | 可能原因 | 处理方法 |
|---|---|---|
| 两端都是 Master(双主) | 心跳口不通、未配置 remote、或 permit_heartbeat 策略缺失 |
检查 display hrp interface 是否为 running,确认 local→dmz 放行 |
hrp enable 后无法在备机配置策略 |
Standby 设备默认禁止配置 | 到主设备上配置,依赖 hrp auto-sync 同步 |
| PC ping 不通虚拟网关 | 两台 FW 的 GE1/0/5 不在同一二层域;或 VIP 与物理 IP 冲突 | 检查 LSW1 端口 VLAN,确认 VIP 规划为 .254 |
| ping 不通防火墙接口 IP(非 VIP) | 未开启管理权限 | 接口下执行 service-manage ping permit |
| 心跳口起不来 | 两端接口编号不同、不在同一区域、或对端 IP 写错 | 两端统一 GE1/0/6、统一 DMZ,remote 指向对端心跳 IP |
| 切换后新连接正常、旧连接中断 | 未开启会话快速备份 | 两端执行 hrp mirror session enable |
八、实验结论
- VRRP 为内网提供了一个稳定的虚拟网关(192.168.1.254),终端无需感知主备设备的存在。
- 华为防火墙的双机热备由 VGMP 统一管理 VRRP 状态 ,因此配置关键字为
active / standby,而不是传统路由器的priority;任一下行业务口故障都会触发整组切换,避免流量黑洞。 - HRP 心跳线同时承担状态协商和会话同步,
hrp mirror session enable是实现"无感知切换"的关键。 - 本实验中,主设备 GE1/0/5 故障或整机宕机后,PC1 仅丢 1~2 个 ICMP 报文即恢复通信,验证了主备冗余的有效性。
- 生产环境建议增加双心跳线、上下行链路监控,并根据需要在主设备上配置延迟抢占,防止链路抖动导致频繁切换。
附录:完整配置命令速查
FW1:
bash
sysname FW1
interface GigabitEthernet0/0/0
ip address 192.168.100.1 255.255.255.0
service-manage all permit
interface GigabitEthernet1/0/5
ip address 192.168.1.251 255.255.255.0
service-manage ping permit
interface GigabitEthernet1/0/6
ip address 10.0.0.1 255.255.255.252
firewall zone trust
add interface GigabitEthernet1/0/5
firewall zone untrust
add interface GigabitEthernet0/0/0
firewall zone dmz
add interface GigabitEthernet1/0/6
security-policy
rule name permit_heartbeat
source-zone local
destination-zone dmz
action permit
interface GigabitEthernet1/0/5
vrrp vrid 1 virtual-ip 192.168.1.254 active
hrp interface GigabitEthernet1/0/6 remote 10.0.0.2
hrp enable
hrp mirror session enable
hrp auto-sync
FW2:
bash
sysname FW2
interface GigabitEthernet0/0/0
ip address 192.168.100.2 255.255.255.0
service-manage all permit
interface GigabitEthernet1/0/5
ip address 192.168.1.252 255.255.255.0
service-manage ping permit
interface GigabitEthernet1/0/6
ip address 10.0.0.2 255.255.255.252
firewall zone trust
add interface GigabitEthernet1/0/5
firewall zone untrust
add interface GigabitEthernet0/0/0
firewall zone dmz
add interface GigabitEthernet1/0/6
security-policy
rule name permit_heartbeat
source-zone local
destination-zone dmz
action permit
interface GigabitEthernet1/0/5
vrrp vrid 1 virtual-ip 192.168.1.254 standby
hrp interface GigabitEthernet1/0/6 remote 10.0.0.1
hrp enable
hrp mirror session enable
hrp auto-sync