0

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?

2 Answers 2

3

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.

  1. Backup the existing file first
  2. 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
2

Most distros will have something like "iptables save". Are you running RedHat/CentOS? Ubuntu?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .