While working on project, I had to bind my Tomcat to port 80 (instead of deploying an Apache and configuring its mod_jk). But, as you should know, Unix systems contains default security rules. Ports below 1024 are only allowed to the root user. Humm... it was time to work with iptables!
The following commands would show you how to add a rule to redirect request on port 80 to port 8080 and how to remove this rule.
Adding a rule :
sudo iptables -t nat -I OUTPUT --src 0/0 --dst [YOUR_IP_HERE] -p tcp --dport 80 -j REDIRECT --to-ports 8080
Saving it :
Listing rules :
sudo iptables -t nat --line-numbers -n -L
This will show rules ordered by REDIRECT, PREROUTING, POSTROUTING and
OUTPUT. Each line start wil a number.
Deleting a rule :
sudo iptables -t nat -D [REDIRECT, PREROUTING, POSTROUTING or OUTPUT] number
Ex : sudo iptables -t nat -D OUTPUT 1