2

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,

#!/bin/bash
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:

#!/bin/bash
/sbin/iptables-restore < /home/amart219/iptables.backup
/sbin/ip6tables-restore < /home/amart219/iptables.backup

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.

Aaron Martin
  • 163
  • 1
  • 5
  • In addition to the above I have tried the methods listed here and it is still not working. https://help.ubuntu.com/community/IptablesHowTo – Aaron Martin Apr 12 '17 at 03:18
  • I would dig through my `init` scripts until I found what I did before. If I was too lazy for that it is time to reinstall. – chicks Apr 18 '17 at 18:49
  • I have only been working with Linux for around 3 months so I am new to a lot of this. Where should I locate my init scripts? – Aaron Martin Apr 19 '17 at 17:39

1 Answers1

0

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.

  • 1
    Thank you! This is what I had done when I first set up iptables, but it had been so long ago I forgot this step, and no solution I googled presented this, therefore everything I tried was overwritten by this file. Now that I have updated this everything is working well. – Aaron Martin Apr 19 '17 at 17:48