Save iptables settings to be persistent on reboot

Save iptables settings to be persistent on reboot

By default, any modification to the iptables rules are not automatically automatically saved, this is how to change that.

(All commands in here should run as root: Running everything as root without sudo on every line)

To save iptables settings to a file, you use the ‘iptables-save’ command, and it can be used like this:

iptables-save > /etc/iptables.rules

To restore settings from a previously saved file, use this:

iptables-restore < /etc/iptables.rules

For settings to be reloaded automatically, you need to execute the above command on every boot, the right way to do it, is by appending a line like this to each interface configuration in ‘/etc/network/interfaces’ file, but, this is not an option on ubuntu desktop or linux mint, since they have the network manager, in that case this should work:

nano /etc/crontab

and append this line to the end:

@reboot  root  iptables-restore < /etc/iptables.rules

Reboot to test the new configuration.

One thought on “Save iptables settings to be persistent on reboot”

  1. Thank you for sharing this tip! In Fedora, I had configured the iptables to automatically restore upon boot by editing saving the iptables output to a file and then redirecting the output to the iptables file (iptables-save > /etc/sysconfig/iptables). However, Linux Mint was different in that Mint doesn’t have directory /etc/sysconfig/iptables, so this tutorial was helpful in knowing how to do the same using crontab. Very cool!

Leave a Reply

Your email address will not be published. Required fields are marked *

(Your message will only be visible after moderation)