0

I have one box running CentOS which is externally facing. Inside the network I have another box running Ubuntu with Apache. I want to be able to access web pages from outside the network which are located on the Ubuntu box. I was told IPTABLES would allow for me to specify the IP Address of my CentOS box and the requests would be forwarded to the Ubuntu box.

I tried following a few tutorials but no dice. Can anyone provide me with the commands to do this?

2 Answers 2

1

On the router:

iptables -t -A PREROUTING -d <public address> -t tcp --dport 80 -j DNAT --to <internal address>:80

This assumes that the CentOS box is running as the default router for the network that the Ubuntu box is on, and that you just want to forward HTTP traffic on the default port.

4
  • If the CentOS box is sitting behind a router this won't work? Why is that?
    – gshauger
    Jul 21, 2011 at 3:46
  • Every computer is "behind" a lot of routers. Please re-read what I wrote.
    – womble
    Jul 21, 2011 at 3:49
  • You said "assumes that the CentOS box is running as the default router". I'm asking why it wouldn't work if it isn't the default router....
    – gshauger
    Jul 21, 2011 at 3:52
  • 1
    That's a different question, and questions go in questions, not comments.
    – womble
    Jul 21, 2011 at 4:06
1

Use DNAT, as womble said:

iptables -t -A PREROUTING -d <public address> -t tcp --dport 80 -j DNAT --to <internal address>:80

but you have to enable ip_forwarding too, and set a minimum of firewall rules

sysctl net.ipv4.ip_forward=1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .