How can I make a specific set of iptables rules permanent?
The simplest method is to use iptables-save and iptables-restore to save the currently-defined iptables rules to a file and (re)load them (e.g., upon reboot).
So, for instance, you would run
sudo iptables-save | sudo tee /etc/iptables.conf
to save your current iptables rules to /etc/iptables.conf
and then insert these lines in /etc/rc.local
:
# Load iptables rules from this file
iptables-restore < /etc/iptables.conf
A Quick Update to this as you might be using 12.04 now and things are better.
The iptables-persistent
package now solves this issue. To install,
sudo apt-get install iptables-persistent
The rules defined when the package is installed are saved and used on each subsequent boots. New rules loaded are discarded at reboot.
The config file if you do need to change them (once iptables-persistent
is installed) is /etc/iptables/rules.v4
or /etc/iptables/rules.v6
for ipv4 and ipv6 iptables respectively.