5

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?

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

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

2

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

0

The "PREROUTING" chain only applies to traffic received from the network. If you want to redirect locally generated traffic you need to use the "OUTPUT" chain.

You probablly also want some matches on the destination IP address.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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