iptables 实现两个网卡端口转发

Posted on Posted in iptables

流程

client0 -> eth0 -> eth1 -> client1

网卡 IP 端口
eth0 1.2.3.4 81
eth1 192.68.0.1
client0 6.7.8.9 1080
client1 192.168.0.2 8180
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp -m tcp --dport 81 -j DNAT --to-destination 192.168.0.2:8180
iptables -t nat -A POSTROUTING -s 192.168.0.0/255.255.0.0 -d 192.168.0.2 -p tcp -m tcp --dport 8180 -j SNAT --to-source 192.168.0.1
iptables -A INPUT -d 192.168.0.2 -p tcp -m tcp --dport 8180 -i eth0 -j ACCEP

Leave a Reply

Your email address will not be published. Required fields are marked *

eleven − 10 =