0

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
  • 3
    You find documentation that explains how to do it for one port, then you repeat that for another port. What have you tried and how did it fail?
    – yoonix
    Feb 10, 2015 at 23:48

1 Answer 1

1

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

1
  • What about Server-side configuration? e.g. VirtualHost directive with apache.
    – ILMostro_7
    Feb 19, 2016 at 6:32

You must log in to answer this question.