I set rules in iptables a few months back and used iptables-persistent to make the rules persist through reboot. I just updated my rules and am trying to make them persist but nothing is working they keep resetting to the earlier version. I have tried:

Creating a cronjob that runs on reboot AND every minute,

iptables-restore -c < /home/amart219/iptables.backup

I have saved to the file that supposedly is default location of the rules and reconfigured iptables-persistent

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

dpkg-reconfigure iptables-persistent I have placed a script in /etc/network/if-pre-up.d/ directory that says the following:

/sbin/iptables-restore < /home/amart219/iptables.backup
/sbin/ip6tables-restore < /home/amart219/iptables.backup

I modified the /etc/network/interfaces file

iface eth0 inet dhcp
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-restore < /etc/iptables.downrules

I added iptables-restore and iptables-save to the if-pre-up.d and if-post-down.d directories in the /etc/network directory

iptables-restore < /etc/iptables.rules
exit 0

iptables-save -c > /etc/iptables.rules
if [ -f /etc/iptables.downrules ]; then
iptables-restore < /etc/iptables.downrules
exit 0

I made sure they were the files were executable.

sudo chmod +x /etc/network/if-post-down.d/iptablessave
sudo chmod +x /etc/network/if-pre-up.d/iptablesload

None of these changes make any difference. My understanding is that dpkg-reconfigure iptables-persistent is the correct method however nothing I try works. I am afraid that some time in the past I might have attempted to make them persistent in some other way that worked prior to installing iptables-persistent but if so I have no idea how I might have done that. I ran: tail -500 /var/log/syslog right after reboot to see if the system loaded anything but I see nothing but the usual boot data. This server has no cron jobs aside from the one that I created trying to restore the iptables setting. I don't know if that is the problem or not, but if it was I don't know how to locate where it might be running from to change it.

If I manually run the script I set up in cron to restore iptables settings, it works just fine but does not persist through reboot. The cronjob is set up properly, on a separate server I have 40+ cronjobs, I am familiar with the process.

Any suggestions? I am not picky on the method I just need it to work.

2 Answers 2


Andrea Turbiglio answered my question on another site. I believe the site is associated with this one but I don't know the rules regarding linking to another site so I am crediting him with the answer and placing it here.

"I used to put the line with "iptables-restore" in /etc/rc.local (tested on both Debian 8 and Ubuntu 16.04) and it worked just fine."


Maybe third-party firewall program is actived. check for ufw and firewalld using

dpkg -l | grep ufw
dpkg -l | grep firewalld

you may install the corresponding gui tools:

sudo apt-get install ufw gufw
sudo apt-get install firewalld firewall-applet
  • This is a terminal only installation, Ubuntu 16.04, with no GUI. Ufw is not installed., I am aware of the program but I only ever use iptables. I would even be willing to try ufw, but I cannot explore that option until I am able to save settings and IP tables since I would need to flush iptables before ufw would work properly Apr 12, 2017 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .