![iptables |从本地 [interface:port] 重定向到本地](https://linux22.com/image/5928/iptables%20%7C%E4%BB%8E%E6%9C%AC%E5%9C%B0%20%5Binterface%3Aport%5D%20%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%E6%9C%AC%E5%9C%B0%20.png)
我有两个接口
eth0 (192.168.1.95) 和 eth0:1 (10.0.0.100)
我想
192.168.1.95:9900(来自任何 192.168/24)的所有数据包将被重定向/转发到 10.0.0.100:9900 并返回(从 10.0.0.100:9900 到 192.168/24)。
帮我用 iptables 做一下。
*nat
-A PREROUTING --dst 192.168.1.95 -p tcp --dport 9900 -j DNAT --to-destination 10.0.0.100
COMMIT
答案1
问题/赞成已经足够清楚了。我可以接受建议,但我就是这么做的。以 root 身份运行这两个命令,然后利用 iptables-save。
来自 192.168.1.95
iptables -t nat -A PREROUTING -s 192.168.1.95 -p tcp --dport 9900 -j DNAT --to-destination 10.0.0.100:9900
从10.0.0.100开始
iptables -t nat -A PREROUTING -s 10.0.0.100 -p tcp --dport 9900 -j DNAT --to-destination 192.168.1.95:9900