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 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

http://ipoftheserver/  

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

http://localhost/

why is that?

thanks in advance.

share|improve this question
add comment

2 Answers

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, http://httpd.apache.org/docs/2.2/bind.html.

httpd.conf

Listen 80
Listen 8000

-or-

Listen 192.0.2.1:80
Listen 127.0.0.1:80
Listen 192.0.2.1:8000
share|improve this answer
add comment

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
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.