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.

~ by Kevin Goodman on April 16, 2012.

One Response to “Linux IPtables Port Redirect”

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 1,374 other followers

%d bloggers like this: