问题原文
原帖链接 · sat · CC BY-SA 3.0
I would like do some NAT in iptables. So that, all the packets coming to 192.168.12.87 and port 80 will be forwarded to 192.168.12.77 port 80.
How to do this with iptables?
Or
Any other ways to achieve the same?
已采纳解答
原帖链接 · krisFR · CC BY-SA 4.0
These rules should work, assuming that iptables is running on server 192.168.12.87 :
#!/bin/sh
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F # DO NOT FLUSH IF YOU'RE SSHING, YOU WILL LOCK YOUR SELF OUT
iptables -t nat -F
iptables -X
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.12.77:80
iptables -t nat -A POSTROUTING -p tcp -d 192.168.12.77 --dport 80 -j SNAT --to-source 192.168.12.87
You have to DNAT incoming traffic on port 80, but you will also need to SNAT the traffic back.
Alternative (and best approach IMHO) :
Depending on what your Web Server is (Apache, NGinx) you should consider an HTTP Proxy on your front-end server (192.168.12.87) :
mod_proxy (Apache)
proxy_pass (NGinx)
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
