pjf*_*pjf 20 iptables port-forwarding
我正在尝试使用iptables. 类似于透明代理。我想捕获任何试图将我的系统留在端口 80 上的内容并将其重定向到远程主机和端口。
我可以使用 NAT 和预路由功能来实现这一点iptables吗?
slm*_*slm 32
试试这个iptables规则:
$ sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination IP:80
Run Code Online (Sandbox Code Playgroud)
上面说的是:
-t nat)。-A) 到出站流量 ( OUTPUT)。-p tcp)感兴趣。--dport 80) 的流量感兴趣。-j DNAT)。--to-destination IP:80)。DNAT
This target is only valid in the nat table, in the PREROUTING and OUTPUT
chains, and user-defined chains which are only called from those chains.
It specifies that the destination address of the packet should be modified
(and all future packets in this connection will also be mangled), and
rules should cease being examined.
Run Code Online (Sandbox Code Playgroud)
小智 6
这可以更具体地仅对特定目标主机的流量进行操作。例如,当 postfix 出错并且队列中的邮件想要发送到旧 IP 地址时。
iptables -t nat -A OUTPUT -p tcp -d {ONLY_TO_THIS_DESTINATION} --dport 25 -j DNAT --to-destination {NEW_IP}:25
Run Code Online (Sandbox Code Playgroud)