我正努力通过iptables
转发一个端口。我做了很多谷歌搜索,但我尝试的所有解决方案都不起作用。
在同一个局域网上用三台计算机进行非常简单的设置
192.168.0.1 # destination
192.168.0.2 # redirector (only one interface)
192.168.0.3 # source
我的iptables
配置也很简单
# iptables -L -n -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:192.168.0.1
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 to:192.168.0.1
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 0.0.0.0/0 0.0.0.0/0
# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
# iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
根据我所读到的,这应该行得通。但事实并非如此,我也曾和iptables -t nat -I POSTROUTING 1 -p tcp -d 192.168.0.1 --dport 443 -j SNAT --to-source 192.168.0.1
玩过,但也不起作用。是的,ip_forward
是启用的。
浏览到192.168.0.2:80/443
应该从192.168.0.1
返回内容,不是吗?有什么想法吗?
发布于 2017-08-11 09:18:51
我让它起作用了!正确的规则是
iptables -t nat -A PREROUTING -d 192.168.0.2 ! -s 192.168.0.1 -p tcp --dport 80 -j DNAT --to 192.168.0.1:80
iptables -t nat -A POSTROUTING -d 192.168.0.1 -p tcp --dport 80 -j SNAT --to 192.168.0.2.
添加-d就能做到这一点。
https://serverfault.com/questions/802303
复制相似问题