设为首页收藏本站language 语言切换
查看: 2002|回复: 0
收起左侧

[分享] 配置分支机构与总部之间通过IPSec Over GRE方式实现安全互通

[复制链接]
发表于 2026-6-10 10:02:14 | 显示全部楼层 |阅读模式
本帖最后由 小乔 于 2026-6-10 10:07 编辑

【实战配置】分支机构与总部之间通过IPSec Over GRE方式实现安全互通

一、组网需求

Router_1为公司分支网关,Router_2为公司总部网关,分支与总部通过公网建立通信。

原本分支与总部通过GRE隧道实现私网互通,现要求对互访流量(不包括组播数据)进行安全保护。

解决方案:基于虚拟隧道接口方式建立IPSec Over GRE隧道,对分支和总部互通的流量进行加密保护。


二、配置思路

1. 配置接口IP地址及公网可达
2. 配置安全提议、IKE提议、IKE对等体、安全框架
3. 配置GRE隧道接口(承载私网互通)
4. 配置IPSec隧道接口(源接口指向GRE隧道,应用安全框架)
5. 配置静态路由,引导私网流量进入IPSec隧道

三、关键配置与注释

1. 分支网关 Router_1 配置


  1. # 配置设备名称
  2. sysname Router_1

  3. # ==================== 1. IPsec安全提议 ====================
  4. ipsec proposal tran1
  5. esp authentication-algorithm sha2-256   # ESP认证算法:SHA2-256
  6. esp encryption-algorithm aes-128        # ESP加密算法:AES-128

  7. # ==================== 2. IKE提议 ====================
  8. ike proposal 5
  9. encryption-algorithm aes-cbc-128        # IKE加密算法:AES-CBC-128
  10. authentication-algorithm sha2-256       # IKE认证算法:SHA2-256

  11. # ==================== 3. IKE对等体 ====================
  12. # 不同版本命令有差异:V200R008前用"ike peer spub v2";V200R008后用"ike peer spub" + "version 2"
  13. ike peer spub v2
  14. pre-shared-key cipher huawei123         # 预共享密钥(两端必须一致)
  15. ike-proposal 5

  16. # ==================== 4. IPsec安全框架 ====================
  17. ipsec profile profile1
  18. ike-peer spub
  19. proposal tran1

  20. # ==================== 5. GRE隧道接口 ====================
  21. interface Tunnel0/0/0
  22. ip address 192.168.1.1 255.255.255.0   # GRE隧道IP(用于源/目的地址)
  23. tunnel-protocol gre
  24. source 202.138.163.1                    # 源地址:公网出接口IP
  25. destination 202.138.162.1               # 目的地址:总部公网IP

  26. # ==================== 6. IPSec隧道接口(关键!) ====================
  27. interface Tunnel0/0/1
  28. ip address 192.168.2.1 255.255.255.0   # IPSec隧道IP(用于路由)
  29. tunnel-protocol ipsec
  30. source Tunnel0/0/0                      # ★ 源接口指向GRE隧道接口
  31. destination 192.168.1.2                 # ★ 目的地址:对端GRE隧道IP
  32. ipsec profile profile1                  # 应用IPsec安全框架

  33. # ==================== 7. 物理接口配置 ====================
  34. interface GigabitEthernet1/0/0
  35. ip address 202.138.163.1 255.255.255.0 # 公网出接口

  36. interface GigabitEthernet2/0/0
  37. ip address 10.1.1.1 255.255.255.0      # 连接分支内网

  38. # ==================== 8. 静态路由 ====================
  39. # 引导分支内网访问总部内网的流量进入IPSec隧道
  40. ip route-static 10.1.2.0 255.255.255.0 tunnel0/0/1

  41. # 公网路由:确保GRE隧道源/目的地址可达
  42. ip route-static 202.138.162.0 255.255.255.0 202.138.163.2

  43. return
复制代码


2. 总部网关 Router_2 配置


  1. # 配置设备名称
  2. sysname Router_2

  3. # ==================== 1. IPsec安全提议 ====================
  4. ipsec proposal tran1
  5. esp authentication-algorithm sha2-256   # 必须与Router_1一致
  6. esp encryption-algorithm aes-128        # 必须与Router_1一致

  7. # ==================== 2. IKE提议 ====================
  8. ike proposal 5
  9. encryption-algorithm aes-cbc-128        # 必须与Router_1一致
  10. authentication-algorithm sha2-256       # 必须与Router_1一致

  11. # ==================== 3. IKE对等体 ====================
  12. ike peer spua v2
  13. pre-shared-key cipher huawei123         # 预共享密钥必须一致
  14. ike-proposal 5

  15. # ==================== 4. IPsec安全框架 ====================
  16. ipsec profile profile1
  17. ike-peer spua
  18. proposal tran1

  19. # ==================== 5. GRE隧道接口 ====================
  20. interface Tunnel0/0/0
  21. ip address 192.168.1.2 255.255.255.0   # GRE隧道IP(对端为192.168.1.1)
  22. tunnel-protocol gre
  23. source 202.138.162.1                    # 源地址:公网出接口IP
  24. destination 202.138.163.1               # 目的地址:分支公网IP

  25. # ==================== 6. IPSec隧道接口 ====================
  26. interface Tunnel0/0/1
  27. ip address 192.168.2.2 255.255.255.0   # IPSec隧道IP(对端为192.168.2.1)
  28. tunnel-protocol ipsec
  29. source Tunnel0/0/0                      # ★ 源接口指向GRE隧道接口
  30. destination 192.168.1.1                 # ★ 目的地址:对端GRE隧道IP
  31. ipsec profile profile1                  # 应用IPsec安全框架

  32. # ==================== 7. 物理接口配置 ====================
  33. interface GigabitEthernet1/0/0
  34. ip address 202.138.162.1 255.255.255.0 # 公网出接口

  35. interface GigabitEthernet2/0/0
  36. ip address 10.1.2.1 255.255.255.0      # 连接总部内网

  37. # ==================== 8. 静态路由 ====================
  38. # 引导总部内网访问分支内网的流量进入IPSec隧道
  39. ip route-static 10.1.1.0 255.255.255.0 tunnel0/0/1

  40. # 公网路由:确保GRE隧道源/目的地址可达
  41. ip route-static 202.138.163.0 255.255.255.0 202.138.162.2

  42. return
复制代码


四、配置验证

验证命令:

  1. display ike sa      # 查看IKE安全联盟
  2. display ipsec sa    # 查看IPsec安全联盟
  3. ping 10.1.2.1       # 测试私网互通性
复制代码


预期结果:
  1. display ike sa
复制代码
显示Flag(s)字段为RD(SA建立成功),Phase字段显示阶段1和阶段2均已建立
PC_1与PC_2可以相互Ping通(私网互通)

五、核心注意事项

⚠️ 关键点1:IPSec Tunnel接口配置
IPSec Tunnel接口的源接口必须指定为GRE Tunnel接口,目的地址必须为对端GRE Tunnel接口的IP地址。这样才能确保IPSec保护的是经过GRE封装后的流量。

⚠️ 关键点2:路由指向
引导私网流量的路由必须指向IPSec Tunnel接口(而非GRE Tunnel接口),否则流量不会被IPsec加密。

⚠️ 关键点3:IKE版本差异
V200R008之前版本使用
  1. ike peer spub v2
复制代码
指定IKEv2;V200R008及之后版本使用
  1. ike peer spub
复制代码
+
  1. version 2
复制代码
。请根据实际设备版本调整。

💡 扩展思路:
如需保护组播/广播流量,GRE Over IPSec(本方案)比IPSec Over GRE更合适
如需高可靠性,可结合VRRP为隧道接口提供冗余备份
如需动态路由,可在GRE隧道接口上运行OSPF,减少静态路由配置

六、总结

本方案通过“GRE隧道 + IPSec隧道”双层隧道嵌套,实现了分支与总部之间的安全加密通信

● GRE隧道:承载私网互通,支持多协议封装
● IPSec隧道:对经过GRE封装的流量进行加密和认证
● 虚拟隧道接口方式:配置简洁,便于管理和路由

该模型适用于分支/总部通过公网互通的场景,尤其适合需要保护组播、非IP协议的复杂网络环境。

互动提问

各位网工朋友,在实际工作中,你更倾向使用IPSec Over GRE还是GRE Over IPSec?遇到过哪些版本差异的坑?欢迎留言分享!

--- 鸿鹄论坛,一路同行 ---

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?论坛注册

x
您需要登录后才可以回帖 登录 | 论坛注册

本版积分规则

QQ|Archiver|手机版|小黑屋|sitemap|鸿鹄论坛 ( 京ICP备14027439号 )  

GMT+8, 2026-8-17 07:16 , Processed in 0.065084 second(s), 9 queries , Redis On.  

  Powered by Discuz!

  © 2001-2025 HH010.COM

快速回复 返回顶部 返回列表