Do I need to restore iptable rules everytime on boot?

Solution 1:

apt-get install iptables-persistent

On install, it should save your current iptables config. Otherwise you can save them to these files (depending on v4 or v6) and iptables-persistent will load them on boot :)

iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6

Solution 2:

First, create a file with the contents of iptables-save:

sudo iptables-save > /etc/iptables_rules

It doesn't really matter where you put the file, all you have to do is make sure that the next line refers to the same file. Next, open /etc/rc.local and add this line:

/sbin/iptables-restore < /etc/iptables_rules

From now on, every time your computer powers up or restarts iptables will load rules from the file that you specified.

Solution 3:

If you do have a lot of rules you should also consider using ipset in conjunction with iptables. Ipset uses an indexed database table and is a lot faster than iptables when looking up an address to decide whether to accept or deny.

http://ipset.netfilter.org/index.html