IPsec 绑定 Loopback 时无法建立
2026/3/13IPSec VPN排错7.X.X大约 3 分钟
IPsec 绑定 Loopback 时无法建立
问题现象
IPSec 隧道绑定到 loopback 接口,且公网出口存在多 ISP 的 ECMP 场景时,IPSec 隧道可能无法建立。

FortiGate 有两个 ISP 出口,默认路由在两个 ISP 出口上等价负载。
FortiGate # get router info routing-table all ...... Routing table for VRF=0 S* 0.0.0.0/0 [10/0] via 101.1.1.1, wan1, [1/0] [10/0] via 202.1.1.1, wan2, [1/0] ......IPSec 连接绑定在 loopback 接口,
local-gw配置为 wan2 的 IP 地址,NAT-T 配置为默认的开启状态(set nattraversal enable)。config vpn ipsec phase1-interface edit "IPSec_Dialup" set type dynamic set interface "loopback1" set ike-version 2 set peertype any set net-device disable set mode-cfg enable set dpd on-idle set eap enable set eap-identity send-request set authusrgrp "IPSec-Group" set ipv4-start-ip 10.13.0.129 set ipv4-end-ip 10.13.0.254 set dns-mode auto set ipv4-split-include "intranet" set nattraversal enable set psksecret xxxxxxxx next endFortiClient 连接 FortiGate 的 IPSec,拨号连接失败。在 FortiClient 侧抓包可以看到一直在重发 IKEv2 第一个协商包(IKE_SA_INIT),FortiGate 没有任何响应。
1 16:10:20.828351600 192.168.1.10 202.1.1.2 a69f9452f9fc9bc4 IKE_SA_INIT MID=00 Initiator Request 2 16:10:23.506134300 192.168.1.10 202.1.1.2 a69f9452f9fc9bc4 IKE_SA_INIT MID=00 Initiator Request 3 16:10:26.510410100 192.168.1.10 202.1.1.2 a69f9452f9fc9bc4 IKE_SA_INIT MID=00 Initiator Request 4 16:10:29.511326300 192.168.1.10 202.1.1.2 a69f9452f9fc9bc4 IKE_SA_INIT MID=00 Initiator Request ......从 FortiGate 处抓包可以看到 FortiGate 从 wan2 接收了 FortiClient 发送的
IKE_SA_INIT,但从 wan1 接口返回了 IKEv2 第 2 个包(IKE_SA_INIT),没有源进源出。R2-601F # diagnose sniffer packet any "host 60.247.121.226" 4 0 l interfaces=[any] filters=[host 60.247.121.226] 2026-03-13 11:14:58.393925 wan2 in 60.247.121.226.500 -> 202.1.1.2.500: udp 328 2026-03-13 11:14:58.393985 wan1 out 202.1.1.2.500 -> 60.247.121.226.500: udp 268 2026-03-13 11:15:04.403999 wan2 in 60.247.121.226.500 -> 202.1.1.2.500: udp 328 2026-03-13 11:15:04.404026 wan1 out 202.1.1.2.500 -> 60.247.121.226.500: udp 268 ......在 FortiGate 上查看 IKEv2 会话,reply 没有遵循 session 优先的原则源进源出,而是独立进行了 RIB 的查找。
session info: proto=17 proto_state=01 duration=0 expire=179 timeout=0 refresh_dir=both flags=00000000 socktype=0 sockport=0 av_idx=0 use=3 origin-shaper= reply-shaper= per_ip_shaper= class_id=0 ha_id=0 policy_dir=0 tunnel=/ vlan_cos=0/0 state=log local may_dirty statistic(bytes/packets/allow_err): org=401/1/1 reply=288/1/1 tuples=2 tx speed(Bps/kbps): 0/0 rx speed(Bps/kbps): 0/0 orgin->sink: org pre->in, reply out->post dev=41->46/46->39 gwy=0.0.0.0/0.0.0.0 hook=pre dir=org act=noop 60.247.121.226:21733->202.1.1.2:500(0.0.0.0:0) hook=post dir=reply act=noop 202.1.1.2:500->60.247.121.226:21733(0.0.0.0:0) misc=0 policy_id=101 pol_uuid_idx=16314 auth_info=0 chk_client_info=0 vd=0 serial=7a971a9d tos=ff/ff app_list=0 app=0 url_cat=0 rpdb_link_id=00000000 ngfwid=n/a npu_state=0x001000 no_ofld_reason: local
问题原因
在未开启强制 NAT-T(set nattraversal forced)的情况下,IKE(IPSec 一阶段)与 ESP(IPSec 二阶段)是独立会话。隧道绑定到 loopback 且存在冗余 ISP 时,IKE 与 ESP 流量可能走不同路径,入向与出向 IKE 协商可能经过不同接口,导致部分客户端无法建立隧道。
解决方法
在 IPSec 一阶段配置中开启 loopback-asymroute 控制 IKE 流量是否允许异步路由,该命令仅在一阶段绑定接口为 loopback 时可见。
config vpn ipsec phase1-interface
edit <name>
set interface <loopback interface name>
set loopback-asymroute {enable | disable}
next
endenable(默认):允许入向/出向 IKE 流量走不同接口(允许异步)。disable:要求入向/出向 IKE 流量走同一接口(源进源出)。