On a CentOS 6 server with an IP address of 172.16.1.10, how can I configure iptables to route traffic destined for 172.16.1.10:80 to 192.168.1.10:80, and traffic destined for 172.16.1.10:8080 to 192.168.1.11:8080? Traffic comes in on eth0 and must leave on eth1. Thanks!
1 Answer
It depends.
If you are talking about http traffic (I'm assuming that from the ports given), proxying might be preferable to using (D)NAT.
IPTables wise this should do it:
iptables -t nat -A PREROUTING -p tcp -d 172.16.1.10 --dport 80 -j DNAT --to 192.168.1.10:80
iptables -t nat -A PREROUTING -p tcp -d 172.16.1.10 --dport 8080 -j DNAT --to 192.168.1.10:8080
possibly related: https://serverfault.com/questions/179200/difference-beetween-dnat-and-redirect-in-iptables
-
What about Server-side configuration? e.g.
VirtualHost
directive withapache
. Feb 19, 2016 at 6:32