如何将请求重定向到本地主机?

时间:2020-02-20 06:10:44

标签: linux networking network-programming firewall iptables

我创建了一个iptables-rule:

-A PREROUTING -s 192.168.XXX.XX/32 -d 192.168.YYY.YY/32 -p tcp -m tcp --dport 65430 -j DNAT --to-destination 127.0.0.1:65435

我什至使用了sysctl -w net.ipv4.ip_forward=1,但仍然无法正常工作。 但是它可以通过以下方式将请求重定向到另一个端口:

-A PREROUTING -s 192.168.XXX.XX/32 -d 192.168.YYY.YY/32 -p tcp -m tcp --dport 65430 -j DNAT --to-destination 192.168.YYY.YY:65435

1 个答案:

答案 0 :(得分:0)

您只需要REDIRECT

iptables -t nat -I PREROUTING -s 192.168.XXX.XX/32 -d 192.168.YYY.YY/32 -p tcp --dport 65430 -j REDIRECT --to-ports 65435