Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
    
If the CentOS box is sitting behind a router this won't work? Why is that? –  gshauger Jul 21 '11 at 3:46
    
Every computer is "behind" a lot of routers. Please re-read what I wrote. –  womble Jul 21 '11 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 '11 at 3:52
1  
That's a different question, and questions go in questions, not comments. –  womble Jul 21 '11 at 4:06

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.