大网数据广告活动
服务器运维问答

VPN : Cannot reach my own gateway using ipsec/strongswan

· 52CE 我爱测

I've followed this tutorial to setup my private VPN using StrongSwan and IPSec. It works very well. But when I try to connect directly to my gateway/server (using SSH), the connection does not go trough the VPN. If I look for the…

问题原文

原帖链接 · iero · CC BY-SA 4.0

I've followed this tutorial to setup my private VPN using StrongSwan and IPSec. It works very well.

But when I try to connect directly to my gateway/server (using SSH), the connection does not go trough the VPN.

If I look for the tables in my client, I see :

$ netstat -nr

Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            link#19            UCS            85        0  ipsec0
default            172.21.15.254      UGScI          18        0     en0
8.8.8.8            link#19            UHWIi           7       33  ipsec0
10.10.10.1         10.10.10.1         UH              0        0  ipsec0
13.32.153.9        link#19            UHW3I           0        3  ipsec0     10
17.248.144.80      link#19            UHWIi           2       22  ipsec0
17.252.76.33       link#19            UHWIi           1       40  ipsec0
18.184.56.218      link#19            UHWIi           1        1  ipsec0
54.37.155.XX       172.21.15.254      UGHS          397      197     en0
...

The last line is added to my client when I connect to the VPN. 54.37.155.XX is the public address of my server. I don't understand what process add this line to my routing table.

If I remove the last line, it works well :

sudo route -n delete 54.37.155.XX 172.21.15.254

I suspect that a missing rule in /etc/ipsec.conf config file is adding this routing entry, but I cannot figure out which one :

config setup
    charondebug="ike 1, knl 1, cfg 0"
    uniqueids=no

conn ikev2-vpn
    auto=add
    compress=no
    type=tunnel
    keyexchange=ikev2
    fragmentation=yes
    forceencaps=yes
    ike=aes256-sha1-modp1024,3des-sha1-modp1024!
    esp=aes256-sha1,3des-sha1!
    dpdaction=clear
    dpddelay=300s
    rekey=no
    left=%any
    leftid=@server_name_or_ip
    leftcert=/etc/ipsec.d/certs/vpn-server-cert.pem
    leftsendcert=always
    leftsubnet=0.0.0.0/0
    right=%any
    rightid=%any
    rightauth=eap-mschapv2
    rightdns=8.8.8.8,8.8.4.4
    rightsourceip=10.10.10.0/24
    rightsendcert=never
    eap_identity=%identity

Any idea ?

已采纳解答

原帖链接 · ecdsa · CC BY-SA 4.0

That's a known problem with macOS/iOS clients. The clients there install a direct route to the VPN server to prevent IKE traffic from getting tunneled via VPN. However, this means you can't access other services via the VPN server's public IP over the VPN either.

As a workaround, you could assign a virtual IP to the server from the subnet you used for virtual IPs assigned to clients. For instance, if you configure rightsourceip=10.10.10.2/24 then you can assign the reserved 10.10.10.1 to one of the server's interfaces and you should be able to access that IP from your VPN client.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-05-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。