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've routed all requests from port 80 to port 8080 for my Tomcat server using iptables.

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

Now works fine, but people can still access I see that on other sites this is not possible. Is there anyway to disable direct access to port 8080 via the url?

share|improve this question
Is there a reason not to simply run your Tomcat server on port 80 natively? – BMDan Jul 21 '10 at 13:47
Apparently that requires giving root access to the Tomcat user and that it's generally a bad idea. That's what I've read, at least. – Matt H Jul 21 '10 at 16:40
up vote 1 down vote accepted

When you access, does it rewrite the URL to If it does, I don't see how to make it work using purely iptables (because you will need the 8080 port to be open to answer the requests). I did a quick test here and the URL was being rewritten but it may be my site doing it.

Said that, maybe it's better to put a nginx or apache with ProxyPass/ProxyPassReverse in front of your application to deal with URLs, with the plus of being able to use nginx's or apache's URL rewrite, load balancing and other capabilities.

share|improve this answer
Thanks, I decided to use nginx. – Matt H Jul 22 '10 at 11:25

I haven't been using iptables for very long now so I wouldn't know how to write the rules for you but I believe if you drop or reject all requests for port 8080 in the filter table then put the statement you provided in the postrouting chain you will get your desired result.

I'm still trying to learn iptables so if this is wrong could you tell me why in the comments?

share|improve this answer

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.