iptables:配置不正确 NAT

iptables:配置不正确 NAT
#port 35001 -> x.x.x.247 (34197)
iptables -t nat -A PREROUTING -p udp -d x.x.x.247 --dport 34197 -j DNAT --to-destination x.x.x.246:35001
iptables -t nat -A POSTROUTING -p udp -s localhost --sport 35001 -j SNAT --to-source x.x.x.247:34197
iptables -t nat -A POSTROUTING -p udp -s x.x.x.246 --sport 35001 -j SNAT --to-source x.x.x.247:34197


#port 35000 -> x.x.x.246 (34197)
iptables -t nat -A PREROUTING -p udp -d x.x.x.246 --dport 34197 -j DNAT --to-destination x.x.x.246:35000
iptables -t nat -A POSTROUTING -p udp -s localhost --sport 35000 -j SNAT --to-source x.x.x.246:34197
iptables -t nat -A POSTROUTING -p udp -s x.x.x.246 --sport 35000 -j SNAT --to-source x.x.x.246:34197

当我尝试使用此配置时,仍然有可能(例如)在远程主机上接收表明它们来自服务器上的端口 35001 的数据包。我该如何转换数据包,以便所有来自端口 35001 的数据包都转换为新的 IP 和端口?

答案1

回答了我自己的问题:我需要使用 -j REDIRECT 而不是 -j DNAT

相关内容