Ubuntu – How to make a specific set of iptables rules permanent

firewalliptablesrebootserverstartup

Is there a "best practice" or standard to make a few iptables rules permanent? I mean: automatically applied upon a system reboot?

I am using a VPS with Ubuntu Server 10.04 LTS (Lucid Lynx).

Thank you.

BIG EDIT: I don't want ANY rule to be persisted (like iptables-persistent package does). I want only my own specific set to be reloaded… if other rules are eventually added by running iptables, these should be discarded…

Best Answer

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