![iptables 在三个接口之间转发流量](https://linux22.com/image/198945/iptables%20%E5%9C%A8%E4%B8%89%E4%B8%AA%E6%8E%A5%E5%8F%A3%E4%B9%8B%E9%97%B4%E8%BD%AC%E5%8F%91%E6%B5%81%E9%87%8F.png)
我试图了解我的 iptables 配置出了什么问题(我是 iptables 的新手)。
我有 3 个接口在同一台机器上运行,并且连接是按以下顺序建立的:
服务器:
tun0:OpenVPN 服务器已建立。
tun1:Openconnect 已建立。
ppp0:Openfortivpn 已建立。
客户:
OpenVPN established to Openvpn on server (tun0).
我想要:
我的客户端上发送到 10.176.86.54 的所有包都从 tun0 到 tun1。
我所有到命运 100.126.20.133 的包都是从 tun0 到 ppp0 的。
所以我做了这样的配置:
sudo iptables -A FORWARD -i tun0 -o ppp0 -d 100.126.20.133 -j ACCEPT
sudo iptables -A FORWARD -i ppp0 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A FORWARD -i tun0 -o tun1 -d 10.176.86.54 -j ACCEPT
sudo iptables -A FORWARD -i tun1 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
所有 VPN 建立后,这是我的 netstat -rn
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 tun1
10.0.0.0 10.111.242.83 255.0.0.0 UG 0 0 0 ppp0
10.8.0.0 10.8.0.2 255.255.255.0 UG 0 0 0 tun0
10.8.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
10.206.145.0 10.111.242.83 255.255.255.128 UG 0 0 0 ppp0
13.80.125.22 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
13.91.91.243 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
40.81.156.154 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
40.90.218.198 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
52.174.56.180 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
52.183.75.62 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
52.184.165.82 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
52.238.78.88 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
52.238.119.141 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
52.244.160.207 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
100.70.132.228 10.111.242.83 255.255.255.255 UGH 0 0 0 ppp0
100.70.133.194 10.111.242.83 255.255.255.255 UGH 0 0 0 ppp0
100.123.0.0 10.111.242.83 255.255.0.0 UG 0 0 0 ppp0
100.125.16.0 10.111.242.83 255.255.255.0 UG 0 0 0 ppp0
100.126.0.0 10.111.242.83 255.255.0.0 UG 0 0 0 ppp0
100.127.4.0 10.111.242.83 255.255.255.0 UG 0 0 0 ppp0
104.42.230.91 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
128.10.0.0 10.111.242.83 255.255.0.0 UG 0 0 0 ppp0
128.14.1.0 10.111.242.83 255.255.255.0 UG 0 0 0 ppp0
131.253.33.215 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
132.147.0.0 10.111.242.83 255.255.0.0 UG 0 0 0 ppp0
135.244.0.0 0.0.0.0 255.255.240.0 U 0 0 0 tun1
135.245.52.100 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
172.16.0.0 10.111.242.83 255.240.0.0 UG 0 0 0 ppp0
190.144.144.252 10.111.242.83 255.255.255.255 UGH 0 0 0 ppp0
190.144.240.101 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
192.0.2.1 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
192.168.0.0 10.111.242.83 255.255.0.0 UG 0 0 0 ppp0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
200.118.0.0 10.111.242.83 255.255.255.128 UG 0 0 0 ppp0
204.79.197.215 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
在我的 openvpn 服务器配置上,我将路由推送到我的客户端:
push "route 10.176.86.0 255.255.255.0"
push "route 100.126.0.0 255.255.0.0"
但如果不起作用,感谢您的支持。