I can add the route like this:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT
--to-port 8080
But after rebooting, it resets. How do I make it permanent? Is the best practice to put it in the rc.local?
IPTables rules are loaded from a file when the service starts.
(The paths below are based on RHEL/CentOS, but the premise should work on other systems)
If you look in /etc/init.d there is an iptables init file, that includes the following lines:
IPTABLES=iptables
IPTABLES_DATA=/etc/sysconfig/$IPTABLES
This file will therefore, load the data from /etc/sysconfig/iptables
when iptables is started.
Once you know which file is used, you can save your current IPTables ruleset to the file.
Add the rule you want to IPTables
iptables-save > /etc/sysconfig/iptables
Try to restart the service and see if the rules persist:
service iptables restart
Most distros will have something like "iptables save". Are you running RedHat/CentOS? Ubuntu?