February
3rd
2014

Forward/Redirect all one port requests to another port on Linux
by

This simple command allows you to forward all requests from PORT_SRC to PORT_DST:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport PORT_SRC -j REDIRECT --to-port PORT_DST

By default, Tomcat runs on port number 8080. One solution is to edit server.xml in order to change the listening port to 80. Otherwise, you can just redirect all port 80 requests to Tomcat’s port 8080 with this command:

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