Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.