IBM Cloud Docs
配置 IPSec 隧道并对其进行故障诊断

配置 IPSec 隧道并对其进行故障诊断

IPSec 隧道用于通过两个路由器或防火墙(通常称为 IPSec 对等端点)之间的协商连接,安全地连接私有空间子网(rfc1918)。 一般来说,两个对等端点通过互联网相互连接。 如果它们没有通过互联网直接连接,则其中一个或两个对等设备可能位于 NAT/端口转发后面。 必须在配置中启用 NAT 穿越。 I

具体来说,在 IBM Cloud 环境中,Vyatta(或其他经典网关设备)被用作 IBM Cloud 经典基础架构侧对等端点。 远程端点(参照 IBM Cloud)是“内部”端的路由器或防火墙。

下图显示了通过互联网从 IBM Cloud Classic 到内部部署的 IPSec 隧道的基本可视化表示。

Vyatta 基本 IPSec 隧道配置
图 1: Vyatta 基本 IPSec 隧道配置

基于路由和基于策略的 IPSec

使用基于路由的 IPSec 时,无需配置流量选择器(也称为本地和远程前缀),而是配置 VTI 接口。 此外,您还可以手动为远程子网配置静态路由,并将下一跳设置为该接口。

对于 Vyatta 上基于策略的 IPSec,需要配置本地和远程前缀,而不需要为隧道配置可路由接口。 添加 VFP 接口是为了给基于策略的 IPSec 配置增加一个可路由接口。 这样就无需迁移到基于路由的配置,以便利用 NAT 和更细粒度的防火墙规则与基于策略的隧道。

要进一步了解基于路由的 IPSec 和基于策略的 IPSec 之间的区别,请参阅 IPsec 站点到站点 VPN 配置选项 一文。

基于路由的 IPSec 配置示例

下面的示例是在 IBM Cloud 经典基础架构环境中运行的基于路由的配置:

西侧

#PHASE 1
set security vpn ipsec ike-group IKE-Fergie ike-version 2
set security vpn ipsec ike-group IKE-Fergie lifetime 28800
set security vpn ipsec ike-group IKE-Fergie proposal 1 dh-group 20
set security vpn ipsec ike-group IKE-Fergie proposal 1 encryption aes256
set security vpn ipsec ike-group IKE-Fergie proposal 1 hash sha2_256

#PHASE 2
set security vpn ipsec esp-group ESP-Fergie pfs dh-group20
set security vpn ipsec esp-group ESP-Fergie proposal 1 encryption aes128gcm128
set security vpn ipsec esp-group ESP-Fergie proposal 1 hash null
set security vpn ipsec esp-group ESP-Fergie lifetime 3600

#Tie it all together configuration
set security vpn ipsec site-to-site peer 159.8.98.213 authentication id 169.50.194.197
set security vpn ipsec site-to-site peer 159.8.98.213 authentication mode pre-shared-secret
set security vpn ipsec site-to-site peer 159.8.98.213 authentication pre-shared-secret '*********'
set security vpn ipsec site-to-site peer 159.8.98.213 authentication remote-id 159.8.98.213
set security vpn ipsec site-to-site peer 159.8.98.213 ike-group IKE-Fergie
set security vpn ipsec site-to-site peer 159.8.98.213 local-address 169.50.194.197
set security vpn ipsec site-to-site peer 159.8.98.213 vti bind vti2
set security vpn ipsec site-to-site peer 159.8.98.213 vti esp-group ESP-Fergie

#VTI INTERFACE CREATION
set interfaces vti vti2 address 172.16.0.5/30

#STATIC ROUTE CREATION FOR REMOTE PREFIX
set protocols static interface-route 10.127.132.128/26 next-hop-interface vti2

#HA considerations - group number can be different on each Vyatta
set interfaces bonding dp0bond1 vrrp vrrp-group 2 notify 'ipsec'

#IKEv2 considerations
set security vpn ike make-before-break

东区

#PHASE 1
set security vpn ipsec ike-group IKE-Fergie ike-version 2
set security vpn ipsec ike-group IKE-Fergie lifetime 28800
set security vpn ipsec ike-group IKE-Fergie proposal 1 dh-group 20
set security vpn ipsec ike-group IKE-Fergie proposal 1 encryption aes256
set security vpn ipsec ike-group IKE-Fergie proposal 1 hash sha2_256

#PHASE 2
set security vpn ipsec esp-group ESP-Fergie pfs dh-group20
set security vpn ipsec esp-group ESP-Fergie proposal 1 encryption aes128gcm128
set security vpn ipsec esp-group ESP-Fergie proposal 1 hash null
set security vpn ipsec esp-group ESP-Fergie lifetime 3600

#Tie it all together configuration
et security vpn ipsec site-to-site peer 169.50.194.197 authentication id 159.8.98.213
set security vpn ipsec site-to-site peer 169.50.194.197 authentication mode pre-shared-secret
set security vpn ipsec site-to-site peer 169.50.194.197 authentication pre-shared-secret '*********'
set security vpn ipsec site-to-site peer 169.50.194.197 authentication remote-id 169.50.194.197
set security vpn ipsec site-to-site peer 169.50.194.197 ike-group IKE-Fergie
set security vpn ipsec site-to-site peer 169.50.194.197 local-address 159.8.98.213
set security vpn ipsec site-to-site peer 169.50.194.197 vti bind vti2
set security vpn ipsec site-to-site peer 169.50.194.197 vti esp-group ESP-Fergie

#VTI INTERFACE CREATION
set interfaces vti vti2 address 172.16.0.6/30

#STATIC ROUTE CREATION FOR REMOTE PREFIX
set protocols static interface-route 10.165.125.112/28 next-hop-interface vti2

#HA considerations - group number can be different on each Vyatta
set interfaces bonding dp0bond1 vrrp vrrp-group 1 notify 'ipsec'

#IKEv2 considerations
set security vpn ike make-before-break

基于接口的防火墙与基于路由的 IPsec

在接口上应用防火墙规则集时,请注意数据包进出接口时的源 IP 和目标 IP。 下图展示了通过 IPSec 隧道在前向和返回路径上穿越 Vyatta 的典型数据包。

IPSec 流量
图 2:IPSec 流量

VTI 的输出方向是数据包加密并从 Vyatta 发送出去的方向。 VTI 的 IN 方向是数据包将被解密并发送到 Vyatta 后面的服务器的地方。 对于外部接口 dp0bond1,数据包将始终是对等端点 IP 地址。 端口/协议为 ESP、UDP 端口 500 和 UDP 端口 4500(如果使用 NAT-T)。

VLAN 接口 (VIF) 输入方向数据包中的源 IP 和目的 IP 应与 VTI 的输出方向相匹配。

以下防火墙规则日志说明了流程:

May 25 05:34:07 gateway02 dataplane[4391]:  In:dp0bond1 PASS fw rule PubIn:1 proto=(other/50) addr=198.11.194.155->159.8.98.214 macs=e4:c7:22:63:b5:41->0:0:5e:0:1:2 v4=(len:156,ttl:241,tos:00,ecn:Not,prot:50,hl:5)
May 25 05:34:07 gateway02 dataplane[4391]:  In:vti0 PASS fw rule INipsecvti0:10 proto=(icmp/1) addr=10.90.72.203->10.126.19.174 v4=(len:84,ttl:63,tos:00,ecn:Not,prot:1,hl:5) icmp=(EchoRq,type:8,code:0)
May 25 05:34:07 gateway02 dataplane[4391]: Out:dp0bond0.1750 PASS fw rule OUTipsec1750:10 proto=(icmp/1) addr=10.90.72.203->10.126.19.174 v4=(len:84,ttl:62,tos:00,ecn:Not,prot:1,hl:5) icmp=(EchoRq,type:8,code:0)
May 25 05:34:07 gateway02 dataplane[4391]:  In:dp0bond0.1750 PASS fw rule INipsec1750:10 proto=(icmp/1) addr=10.126.19.174->10.90.72.203 v4=(len:84,ttl:64,tos:00,ecn:Not,prot:1,hl:5) icmp=(EchoRp,type:0,code:0)
May 25 05:34:07 gateway02 dataplane[4391]: Out:vti0 PASS fw rule OUTipsecvti0:10 proto=(icmp/1) addr=10.126.19.174->10.90.72.203 v4=(len:84,ttl:63,tos:00,ecn:Not,prot:1,hl:5) icmp=(EchoRp,type:0,code:0)
May 25 05:34:07 gateway02 dataplane[4391]: Out:dp0bond1 PASS fw rule PubOut:1 proto=(other/50) addr=159.8.98.214->198.11.194.155 v4=(len:156,ttl:255,tos:00,ecn:Not,prot:50,hl:5)

基于区域的防火墙与基于路由的 IPSec

对于基于区域的防火墙,您定义的策略应假定流量在 VTI 接口和 VRA 的本地专用 VLAN 接口 (VIF) 之间流动。 您无需在 VTI 和 dp0bond1 区域之间定义策略。

基本故障排除

要排除 IPSec 隧道配置问题,请执行以下流程:

  1. 重置隧道并重新启动 VPN。

    如果可以,请先这样做,因为这样可以节省停电时的时间。 确保记住每条命令要重启的内容及其对其他隧道的影响。

  2. 检查对等设备之间的端到端网络连接。

    确保允许两个对等设备的外部接口使用 UDP 端口 500 和 4500(如果使用 NAT-T)以及 ESP 协议。

  3. 检查第 1 阶段状态。 停机 "状态可能意味着

    • 您没有检查第 2 步
    • IKE 版本、加密算法、哈希算法或 IKE 标识不匹配
    • 与供应商不兼容
  4. 检查第 2 阶段状态。 宕机 "状态(或根本没有状态)可能意味着

    • 第 1 阶段已关闭
    • 加密算法、哈希算法、流量选择器或 dh 组不匹配
    • 存在供应商不兼容问题
  5. 解析可用的 IPsec 日志,查找问题迹象。 日志可以为您提供不匹配的准确信息,帮助您快速解决问题。

  6. 查看 VRA 软件补丁,了解有关常见错误的信息。 您还可以向 IBM Cloud安全支持部门索取全面的 PDF 文件。

故障排除命令

检查第 1 阶段状态:

show vpn ike sa
show vpn ike sa peer <Peer IP>

样本输出:

vyatta@siferguson-par01-02:~$ show vpn ike sa peer 169.50.194.197
Peer ID / IP                            Local ID / IP
------------                            -------------
169.50.194.197                          159.8.98.213

    State    Encrypt       Hash    D-H Grp  A-Time  L-Time IKEv
    -----  ------------  --------  -------  ------  ------ ----
    up     aes256        sha2_256  14       2154    3600    2

检查第 2 阶段状态:

show vpn ipsec sa
show vpn ipsec sa peer <Peer IP>

样本输出:

vyatta@siferguson-par01-02:~$ show vpn ipsec sa peer 169.50.194.197
Peer ID / IP                            Local ID / IP
------------                            -------------
169.50.194.197                          159.8.98.213

    Tunnel  Id          State  Bytes Out/In   Encrypt       Hash      DH A-Time  L-Time
    ------  ----------  -----  -------------  ------------  --------  -- ------  ------
    vti     44          up     284.3M/27.2G   aes128gcm128  null      n/a 2131    300

快速显示特定对等连接的详细信息:

show vpn debug peer <Peer IP>

样本输出:

vyatta@siferguson-par01-02:~$ show vpn debug peer 169.50.194.197
peer-169.50.194.197:  159.8.98.213...169.50.194.197  IKEv2
peer-169.50.194.197:   local:  [159.8.98.213] uses pre-shared key authentication
peer-169.50.194.197:   remote: [169.50.194.197] uses pre-shared key authentication
peer-169.50.194.197-tunnel-vti:   child:  0.0.0.0/0 === 0.0.0.0/0 TUNNEL
peer-169.50.194.197[48]: ESTABLISHED 38 minutes ago, 159.8.98.213[500][159.8.98.213]...169.50.194.197[500][169.50.194.197]
peer-169.50.194.197[48]: IKEv2 SPIs: 65967eb4beab8549_i 1eacdfa5f926b9a3_r*, pre-shared key reauthentication in 13 minutes
peer-169.50.194.197[48]: IKE proposal: AES_CBC_256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_2048
peer-169.50.194.197-tunnel-vti{44}:  INSTALLED, TUNNEL, reqid 1, ESP SPIs: 9796e1b4_i db89cc43_o
peer-169.50.194.197-tunnel-vti{44}:  AES_GCM_16_128, 31436172664 bytes_i, 322001309 bytes_o, rekeying active
peer-169.50.194.197-tunnel-vti{44}:   0.0.0.0/0 === 0.0.0.0/0

{: screen|

显示和解析可用的 IPSec 日志:

show log vpn ipsec
show log vpn ipsec subsystem ike-sa site-to-site peer <Peer IP>
journalctl -f -u strongswan #This live follows the end of the journal logs for ipsec
journalctl -u strongswan > /home/vyatta/journalctl-ipsec-$(date +%Y%m%d) #this creates a file so that you can parse/grep through the logs without them rotating

重置 IPSec 隧道:

 reset vpn ipsec-peer <Peer IP> #reset all tunnels/phase 2's on this peer
 reset vpn ipsec-peer <Peer IP> tunnel <tunnel id> #reset phase 2 tunnel for only the specified tunnel on the specified peer
 restart vpn #This restarts the entire IPSec VPN subsystem - this affects all tunnels on all peers

常见问题

下面列出了 IPSec 隧道可能遇到的一些常见问题。

  • 两个对等节点之间的第 1 阶段和第 2 阶段参数不匹配。
  • IKE 版本不匹配。
  • 第 1 阶段失败,出现身份验证错误,而一切似乎都匹配。
    • 确保将身份验证 ID 和远程 ID 设置为本地和远程 IP 地址。
  • 外部接口不允许使用 ESP 和 UDP 端口 500 和 4500。
    • 确保允许使用 ESP 和端口 500。 如果使用 NAT-T,请确保允许 UDP 4500。
  • Ciena 建议您在使用 IKEv2 时使用 set security vpn ike make-before-break 行。 省略这一行可能会导致断电。
  • 吞吐速度慢。
    • 使用 aes128gcm 或 aes256gcm 作为第 2 阶段加密算法。 如果之前的加密算法是标准的 AES128 或 AES256,那么这将大大提高吞吐量。
    • 如果已实施按数据包记录,则禁用按数据包记录。 按数据包记录防火墙日志会降低吞吐量。
  • IPSec 隧道可以正常工作,但重新键入后就会中断。
    • 检查两个对等设备上的 PFS 和 dh 组是否匹配。
  • show vpn ipsec sa 命令只显示一个方向的增量。
    • 这通常是由非对称路由造成的,即一方通过隧道发送数据,而另一方不通过隧道发送数据。
  • 使用运行转换脚本进行 HA 故障切换,而不是替换 notify 命令。

其他资源

在配置 IPSec 隧道和排除故障时,以下列表提供了一些其他资源: