技术解析

请教一个关于 iptables 转发 IPsec VPN 的问题
0
2021-06-23 09:44:52
idczone
先上个效果

WAN Computer -- (eth1/80.10.3.5)Server1(eth0/10.10.2.4) -- (eth0/10.11.2.3)Server2(eth1/111.1.1.2) -- WAN

现在手上有两个服务器,打算拿 server1 做跳板连接到 server2 的 IPsec VPN server,但是尝试配置了 iptables 之后无法通过 server1 的 IP 连接到 server2,VPN Server 是 l2tp with IPsec 和 Cisco IPsec 都配置有的。

内网可以通信

eth1 是外网接口,eth0 是内网接口

尝试的配置如下

iptables -t nat -A POSTROUTING -p udp -d 10.11.2.3 --dport 4500 -j SNAT --to-source 10.10.2.4
iptables -t nat -A POSTROUTING -p udp -d 10.11.2.3 --dport 500 -j SNAT --to-source 10.10.2.4
iptables -t nat -A POSTROUTING -p udp -d 10.11.2.3 --dport 1701 -j SNAT --to-source 10.10.2.4
iptables -t nat -A PREROUTING -p udp --dport 500 -j DNAT --to-destination 10.11.2.3
iptables -t nat -A PREROUTING -p udp --dport 4500 -j DNAT --to-destination 10.11.2.3
iptables -t nat -A PREROUTING -p udp --dport 1701 -j DNAT --to-destination 10.11.2.3
iptables -A FORWARD -p esp -j ACCEPT
iptables -A FORWARD -p ah -j ACCEPT

测试了转发至 server2 上的 httpd 之类的都可以正常链接,请问是哪里配置错了呢?
IP 转发开了么?
修改 /etc/sysctl.conf,设置 net.ipv4.ip_forward = 1。重启。

一个小问题:配置前几行中 nat table 限定了 UDP 协议,最后 filter table 怎么换成了 esp 和 ah 呢?

iptables -t nat -A PREROUTING -p udp --dport 500 -j DNAT --to-destination 10.11.2.3:500
iptables -t nat -A POSTROUTING -d 10.11.2.3 -p udp -m udp --dport 500 -j SNAT --to-source 10.10.2.4
iptables -t nat -A PREROUTING -p udp --dport 4500 -j DNAT --to-destination 10.11.2.3:500
iptables -t nat -A POSTROUTING -d 10.11.2.3 -p udp -m udp --dport 4500 -j SNAT --to-source 10.10.2.4
iptables -t nat -A PREROUTING -p udp --dport 1701 -j DNAT --to-destination 10.11.2.3:1701
iptables -t nat -A POSTROUTING -d 10.11.2.3 -p udp -m udp --dport 1701 -j SNAT --to-source 10.10.2.4

开 ssh,让我上去试试

IPsecVPN 穿越放火墙需要放过的只有 ike 协议(UDP500),NAT-T(UDP4500),esp 协议( IP 协议号 50 )。AH 没人用的。

ip 转发开了的,ss 之类的都可以链接

感谢回复
不过有一点疑问,在第三行的 prerouting 里面,为什么要把 4500 转发到 500 呢?
还有就是 postrouting 除了增加了 extend match 似乎和我在主题上贴的没有区别。另外按照指教的参数配置后还是没有转发成功

不好意思打错了。。。我这个是用来转发 WebDAV 的和 ssh 的 tcp 流量的,我是可以用的

哪里的 vps,有的 vps 商是带防火墙管理的,比如谷歌云,需要在外面手动再次配置一次防火墙

不好意思 看错了 以为是 vps

还在用 IPSec ?这种分分钟给你断掉

换 ssl vpn 吧

又不是用来绕过某个设备用的

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服