我有以下情况。
家庭网络位于 192.168.1.0/24 上,使用能够处理 IPSec 隧道的 Zyxel USG50。远程 VPS 运行 Ubuntu 16.04 并托管 PPTP 服务器 (10.0.0.1),该服务器将地址 10.0.0.100-200 分配给客户端。PPTP 服务器运行完美,客户端可以毫无问题地浏览互联网。
现在,我正在设置 IPSec 隧道,以便能够通过 PPTP 连接设备访问我的家庭网络设备。无论如何,通信似乎只能单向进行:我可以从家庭网络(例如 192.168.1.4)ping 连接 VPN 的设备(例如 10.0.0.100),但反之则不行。此外,VPS 无法 ping 192.168.1.0 网络上的设备(数据包通过互联网传出)
ipsec配置文件
conn home
authby = secret
keyexchange = ikev1
ikelifetime = 86400
lifetime = 28800
ike = aes256-sha512-modp2048!
esp = aes256-sha512-modp2048!
auto = add
left = %any
leftsubnet = 10.0.0.0/24
leftfirewall = yes
right = (my_ddns_home_address)
rightid = %any
rightsubnet = 192.168.1.0/24
ipsec 状态
Security Associations (1 up, 0 connecting):
home[1]: ESTABLISHED 30 minutes ago, my_vpsip[my_vps_ip]...my_home_ip[my_home_ip]
home{1}: INSTALLED, TUNNEL, reqid 1, ESP SPIs: ce9b32e6_i 96369de8_o
home{1}: 10.0.0.0/24 === 192.168.1.0/24
是否配置
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:89426 errors:0 dropped:0 overruns:0 frame:0
TX packets:89426 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:30719387 (30.7 MB) TX bytes:30719387 (30.7 MB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.0.0.1 P-t-P:10.0.0.100 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1396 Metric:1
RX packets:32314 errors:0 dropped:0 overruns:0 frame:0
TX packets:44911 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:3108413 (3.1 MB) TX bytes:49298247 (49.2 MB)
venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:127.0.0.2 P-t-P:127.0.0.2 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
RX packets:12701126 errors:0 dropped:0 overruns:0 frame:0
TX packets:11210758 errors:0 dropped:7605 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11729004253 (11.7 GB) TX bytes:3015436822 (3.0 GB)
venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:vps_public_ip P-t-P:212.24.96.165 Bcast:vps_public_ip Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
iptables -L -n -v
Chain FORWARD (policy ACCEPT 1060 packets, 436K bytes)
pkts bytes target prot opt in out source destination
3 180 ACCEPT all -- venet0 * 192.168.1.0/24 10.0.0.0/24 policy match dir in pol ipsec reqid 1 proto 50
9 540 ACCEPT all -- * venet0 10.0.0.0/24 192.168.1.0/24 policy match dir out pol ipsec reqid 1 proto 50
ip 路由显示表 220
192.168.1.0/24 via my_home_ip dev venet0 proto static src 10.0.0.1
答案1
通过添加此 iptables 规则解决:
sudo iptables -t nat -I POSTROUTING 1 -j ACCEPT -s 10.0.0.0/24 -m policy --dir out --pol ipsec
请参阅此处了解更多详细信息:Strongswan VPN 隧道已连接,但流量未通过它路由