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 an apache server running on 8100. When open http://localhost:8100 in browser we will see the site running correctly.

Now I would like to direct all request on 80 to 8100 so that the site can be accessed without the port number. I am not familiar with iptables so I searched for solutions online. This is one of the methods that I have tried:

user@ubuntu:~$ sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
user@ubuntu:~$ sudo iptables -A INPUT -p tcp --dport 8100 -j ACCEPT
user@ubuntu:~$ sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8100

It's not working. The site works on 8100 but it's not on 80. If print out the rules using "iptables -t nat -L -n -v", this is what I see:

user@ubuntu:~$ sudo iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 14 packets, 2142 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REDIRECT   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           
tcp dpt:80 redir ports 8100 

Chain INPUT (policy ACCEPT 14 packets, 2142 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 177 packets, 13171 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 177 packets, 13171 bytes)
 pkts bytes target     prot opt in     out     source               destination 

The OS is a Ubuntu on a VMware. I thought this should be a simple task but I have been working on it for hours without success. :( What am I missing?

share|improve this question
add comment

migrated from stackoverflow.com Nov 18 '11 at 15:53

This question came from our site for professional and enthusiast programmers.

1 Answer

Try: sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to 127.0.0.1:8100

share|improve this answer
add comment

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.