华为防火墙:实战配置GRE over IPSec隧道与安全策略

1. GRE over IPSec技术背景与应用场景

企业跨地域组网时,经常需要将两个私有网络通过公网安全连接。这时候GRE over IPSec技术就派上用场了。简单来说,GRE负责在两点间建立虚拟隧道,而IPSec则为这条隧道提供加密保护,就像在公共道路上修建了一条专属的加密管道。

实际项目中,我遇到过不少客户需要连接总部和分支机构的案例。比如某零售企业要在30家门店和总部间传输销售数据,直接暴露在公网上显然不安全。用普通GRE隧道虽然能连通,但数据是明文的,用纯IPSec又无法支持组播等特殊协议。GRE over IPSec正好结合了两者优势:既保持GRE的多协议支持特性,又具备IPSec的加密能力。

这个方案特别适合以下场景:

  • 需要传输OSPF、RIP等路由协议
  • 视频监控等组播应用
  • 跨区域办公网络互联
  • 对传输安全性要求较高的金融、医疗等行业

2. 华为防火墙基础环境准备

2.1 网络拓扑规划

我们先来看典型的两点组网拓扑。假设有总部FW-A和分支机构FW-B两台华为防火墙,各自下联内部网络,上联公网接口:

[FW-A] 公网IP 10.1.1.1/30 —— 互联网 —— 20.1.1.1/30 [FW-B] | | 172.16.10.0/24 172.16.20.0/24 (总部内网) (分支机构内网)

配置前需要确认:

  1. 公网接口IP已正确配置且能互通
  2. 内网接口IP和区域划分已完成
  3. 防火墙安全区域(trust/untrust)已绑定对应接口

2.2 基础网络配置

以FW-A为例,基础配置命令如下:

# 配置公网接口 [FW-A] interface GigabitEthernet 1/0/0 [FW-A-GigabitEthernet1/0/0] ip address 10.1.1.1 30 [FW-A-GigabitEthernet1/0/0] quit # 配置内网接口 [FW-A] interface GigabitEthernet 1/0/1 [FW-A-GigabitEthernet1/0/1] ip address 172.16.10.254 24 [FW-A-GigabitEthernet1/0/1] quit # 绑定安全区域 [FW-A] firewall zone untrust [FW-A-zone-untrust] add interface GigabitEthernet1/0/0 [FW-A-zone-untrust] quit [FW-A] firewall zone trust [FW-A-zone-trust] add interface GigabitEthernet1/0/1 [FW-A-zone-trust] quit

记得在FW-B上做镜像配置,把公网IP改为20.1.1.1,内网网段改为172.16.20.0/24。

3. GRE隧道建立与配置

3.1 创建Tunnel接口

GRE隧道的核心是虚拟的Tunnel接口。在FW-A上配置:

[FW-A] interface Tunnel 1 [FW-A-Tunnel1] description to_network-b [FW-A-Tunnel1] ip address 1.1.1.1 24 # 隧道虚拟IP [FW-A-Tunnel1] tunnel-protocol gre # 指定GRE协议 [FW-A-Tunnel1] source 10.1.1.1 # 本端公网IP [FW-A-Tunnel1] destination 20.1.1.1 # 对端公网IP [FW-A-Tunnel1] gre key cipher 123456 # 隧道密钥 [FW-A-Tunnel1] quit

这里有几个关键点:

  • tunnel-protocol必须指定为gre
  • source/destination要填写实际的公网IP
  • gre key两端必须一致,建议使用复杂字符串

3.2 创建GRE安全区域

为了精细化管理流量,建议为GRE隧道创建独立安全区域:

[FW-A] firewall zone name gre [FW-A-zone-gre] set priority 10 [FW-A-zone-gre] add interface Tunnel1 [FW-A-zone-gre] quit

优先级设为10是介于trust(85)和untrust(5)之间,方便后续策略控制。

3.3 静态路由配置

要让内网流量走GRE隧道,需要添加静态路由:

# 默认路由指向公网下一跳 [FW-A] ip route-static 0.0.0.0 0.0.0.0 10.1.1.2 # 到对端内网的路由指向Tunnel接口 [FW-A] ip route-static 172.16.20.0 255.255.255.0 Tunnel 1

测试时可以用ping -a 172.16.10.1 172.16.20.1指定源IP测试连通性。

4. IPSec安全策略配置

4.1 定义感兴趣流ACL

首先用ACL定义需要加密的流量,即GRE隧道流量:

[FW-A] acl number 3000 [FW-A-acl-adv-3000] rule 5 permit ip source 10.1.1.1 0 destination 20.1.1.1 0 [FW-A-acl-adv-3000] quit

这个ACL表示:源是本端公网IP,目的是对端公网IP的流量需要加密。

4.2 IKE协商配置

IKE阶段1配置包括:

# IKE提议(加密算法配置) [FW-A] ike proposal 10 [FW-A-ike-proposal-10] encryption-algorithm aes-256 [FW-A-ike-proposal-10] dh group18 [FW-A-ike-proposal-10] authentication-algorithm sha2-512 [FW-A-ike-proposal-10] authentication-method pre-share [FW-A-ike-proposal-10] integrity-algorithm hmac-sha2-256 [FW-A-ike-proposal-10] prf hmac-sha2-256 [FW-A-ike-proposal-10] quit # IKE对等体 [FW-A] ike peer fw [FW-A-ike-peer-fw] exchange-mode main [FW-A-ike-peer-fw] pre-shared-key huawei@123 # 预共享密钥 [FW-A-ike-peer-fw] ike-proposal 10 [FW-A-ike-peer-fw] remote-address 20.1.1.1 [FW-A-ike-peer-fw] quit

注意:预共享密钥需要两端相同,建议使用复杂密码并定期更换。

4.3 IPSec策略配置

IKE阶段2配置IPSec参数:

# IPSec提议 [FW-A] ipsec proposal 10 [FW-A-ipsec-proposal-10] transform esp [FW-A-ipsec-proposal-10] encapsulation-mode tunnel [FW-A-ipsec-proposal-10] esp authentication-algorithm sha2-512 [FW-A-ipsec-proposal-10] esp encryption-algorithm aes-256 [FW-A-ipsec-proposal-10] quit # IPSec策略 [FW-A] ipsec policy ipsec 1 isakmp [FW-A-ipsec-policy-isakmp-ipsec-1] security acl 3000 [FW-A-ipsec-policy-isakmp-ipsec-1] ike-peer fw [FW-A-ipsec-policy-isakmp-ipsec-1] proposal 10 [FW-A-ipsec-policy-isakmp-ipsec-1] quit

最后将策略应用到公网接口:

[FW-A] interface GigabitEthernet1/0/0 [FW-A-GigabitEthernet1/0/0] ipsec policy ipsec [FW-A-GigabitEthernet1/0/0] quit

5. 安全策略与调试技巧

5.1 防火墙安全策略配置

华为防火墙默认拒绝所有流量,需要手动放行:

[FW-A] security-policy # 放行本端到对端的IKE协商 [FW-A-policy-security] rule name local_remote [FW-A-policy-security-rule-local_remote] source-zone local [FW-A-policy-security-rule-local_remote] destination-zone untrust [FW-A-policy-security-rule-local_remote] source-address 10.1.1.1 32 [FW-A-policy-security-rule-local_remote] destination-address 20.1.1.1 32 [FW-A-policy-security-rule-local_remote] service ike [FW-A-policy-security-rule-local_remote] action permit [FW-A-policy-security-rule-local_remote] quit # 放行内网到GRE隧道的业务流量 [FW-A-policy-security] rule name trust_gre [FW-A-policy-security-rule-trust_gre] source-zone trust [FW-A-policy-security-rule-trust_gre] destination-zone gre [FW-A-policy-security-rule-trust_gre] source-address 172.16.10.0 24 [FW-A-policy-security-rule-trust_gre] destination-address 172.16.20.0 24 [FW-A-policy-security-rule-trust_gre] action permit [FW-A-policy-security-rule-trust_gre] quit

5.2 常见问题排查

遇到隧道不通时,可以按以下步骤排查:

  1. 检查物理连通性

    ping 20.1.1.1
  2. 查看IKE SA状态

    display ike sa

    如果看不到SA,可能是IKE协商失败,检查预共享密钥和提案配置。

  3. 查看IPSec SA状态

    display ipsec sa

    没有SA说明第二阶段协商失败,检查ACL和IPSec提案。

  4. 抓包分析

    capture-packet interface GigabitEthernet1/0/0

    观察是否有加密的ESP报文。

  5. 查看路由表

    display ip routing-table

    确认172.16.20.0/24的路由指向Tunnel接口。

5.3 性能优化建议

在实际部署中,还可以考虑:

  • 启用DPD(Dead Peer Detection)检测对端存活
  • 调整SA生存时间,平衡安全性和性能
  • 对重要隧道配置备份链路
  • 启用QoS保证关键业务带宽

有一次给客户部署时,发现隧道时断时续,后来发现是MTU问题。GRE和IPSec都会增加报文头,建议在内网接口设置MTU 1400:

[FW-A] interface GigabitEthernet1/0/1 [FW-A-GigabitEthernet1/0/1] mtu 1400