Linux IPtables Port Redirect
So a few days ago we needed to do a port redirect on a server. This was a new implementation of an app server, but the link for all the clients refered to port 80. The new install listed on port 8080.
A few ideas were kicked around like installing apache to listen and do a metaredirect to the new location. Then it clicked, why not use IPtables?
Below is how we redirected port 80 to 8080
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
Once completed and tested, I saved the config as follows
iptables-save > /etc/sysconfig/iptables
The above is for a RedHat Linux server. IPtables pulls its config from /etc/sysconfig/iptables file on startup.

Thanks. I also would like to know how to close the 8080 from outside.
I have tomcat listening on 8080 and I successfully redirected 80 on 8080. But I had to open both 80 and 8080 for this to work. I’d like to close the 8080 at least from the outside, so that tomcat would be accessible ONLY on 80. I think I have to open 8080 internally, on localhost, but I have troubles with the sintax. any help? Thanks
Conrad said this on May 16, 2012 at 7:04 am