Make Ubuntu iptables Rules Persistent Across Restart

By default, Ubuntu (desktop) is different than Fedora in terms of iptables rules persistence. Ubuntu’s iptables rules are live and not persistent, so that Ubuntu’s rule will always reset after system restart.

There are many ways to make it persistent, the one easy to do that is installing iptables-persistent package using apt-get. Below is a terminal output while installing iptables-persistent package. During installation, you will prompted whether you want to save current iptables rules or not.

root@ubuntu:~# apt-get install iptables-persistent
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 8,960 B of archives.
After this operation, 58.4 kB of additional disk space will be used.
Get:1 precise/universe iptables-persistent all 0.5.3ubuntu2 [8,960 B]
Fetched 8,960 B in 0s (13.3 kB/s) 
Preconfiguring packages ...
Selecting previously unselected package iptables-persistent.
(Reading database ... 174002 files and directories currently installed.)
Unpacking iptables-persistent (from .../iptables-persistent_0.5.3ubuntu2_all.deb) ...
Processing triggers for ureadahead ...
ureadahead will be reprofiled on next reboot
Setting up iptables-persistent (0.5.3ubuntu2) ...
 * Loading iptables rules... * IPv4... * IPv6... [ OK ] 

This package will make Ubuntu’s iptables rules persistent by storing iptables rules in:

  • /etc/iptables/rules.v4 for IPv4 rules
  • /etc/iptables/rules.v6 for IPv6 rules

Any of those rules will be reloaded to current iptables rules during restart. You can save your current iptables rules manually by using the following command:

root@ubuntu:~# iptables-save > /etc/iptables/rules.v4

Don’t forget, you have to be root in order to be able to do that, or you may append the command with sudo. This one has been tested by me on Ubuntu Desktop 12.04LTS Precise Pangolin.

Linux ubuntu 3.5.0-32-generic #53~precise1-Ubuntu SMP Wed May 29 20:35:31 UTC 2013 i686 i686 i386 GNU/Linux