Automatically loading iptables in Debian and Ubuntu Linux

Debian doesn’t have an automatic way of loading up iptables, so if you use Debian, or Ubuntu you might be wondering why everytime you restart you lose your iptables rules. And if you got that far your probably wondering where the default iptables file is stored. Here is news, there is no file store! You have to make it! Here is how I did it.

1. Save your existing firewall rules to a file for later execution

iptables-save > /etc/firewall.conf 

2. Configure a firewall load command in if-up.d network startup script folder.

iptables-restore < /etc/firewall.conf

3. Make sure that the script you've put in the if up auto configuration is executable

chmod +x /etc/network/if-up.d/iptables

4. Now when you add new iptables rules you can run a save command

iptables-save > /etc/firewall.conf

or you can just edit the startup file, which will become active next reboot

vi /etc/firewall.conf 

This is one of the most elegant and simple ways to configure iptables, thanks to Major Hayden, a fellow Rackspace employee for this tip.