Load iptables on boot Ubuntu


There is no iptables service avilable in Ubuntu like service iptables start and service iptables stop. Because of this we can’t start iptables boot.

There is small hack to start iptables on boot in Ubuntu/Debian. I will be explaining it here.

First write all you iptables rules in your Ubuntu machine.

Then save you need to save iptables rules in a text file with iptables-save command.

$ sudo iptables-save > iptables_rules

Copy or move iptables_rules file in to some directory (H ere I am using /etc/sysconfig/).

Now open /etc/network/interfaces to edit and add following line below iface lo inet loopback,  then save and exit.

pre-up iptables-restore /etc/sysconfig/iptables_rules

Now reboot and test for iptables rules.

To test run sudo iptables -L command, and you should see the rules you added.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s