Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a web server running on port 8080. I'd like to visit it via port 80, so I did this:

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-port 8080

it works if i access the server from other machines using


but it doesn't work if I access the server from the same machine using


why is that?

thanks in advance.

share|improve this question
up vote 3 down vote accepted

I'm not sure you can do what you want via iptables, localhost doesn't go through the NAT routing. See this SO question and this SF question for details.

You can make the server bind to multiple ports if it's Apache. See this page for details,


Listen 80
Listen 8000


share|improve this answer

The PREROUTING chain affects received packets before they are routed. Locally-generated packets start at the OUTPUT chain.

share|improve this answer
you are absolutely right. thank you. – David Dai Jan 16 '13 at 4:31

Your Answer


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.