Port forwarding from port 80 to port 8080 with iptables

If you need to do port forwarding from port 80 to port 8080 (maybe you are running tomcat on port 8080) you can do it with iptables like this:

sudo iptables -A PREROUTING -d $HOSTNAME -p tcp --dport 80 -j REDIRECT --to-ports 8080 -t nat

If you want to revert the change to iptables do this:

sudo iptables -F -t nat

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>