Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write two persistent NAT rules, which I save via iptables-save > /etc/iptables.ipv4.nat, and restore upon reboot via pre-up iptables-restore < /etc/iptables.ipv4.nat in my /etc/network/interfaces. Prior to reboot, the rules display when iptables -t nat -L is used, but after reboot the rules seem to return to their default. Curiously, when I inspect the file to which I saved the rules, they are still present.

So what's happening, and how do I fix it (if it requires fixing at all)?

share|improve this question
Can you check for errors on the pre-up line, and see if running the iptables-restore manually works as expected? – fooot Mar 25 '14 at 15:49
Is it possible that a file permission on the saved file is causing you trouble? – David Wilkins Mar 25 '14 at 16:53
Apologies for the late reply! I could find no errors on the pre-up line, but running iptables-restore manually did work as expected. – Anon Mar 26 '14 at 16:44
As a workaround, I've written the iptables-restore command to /etc/rc.local instead, but I'd still be interested to know why my original method didn't work as expected. I also tried writing the rules out in /etc/network/interfaces rather than using save and restore, and that didn't work either, so maybe it's a problem with that file? – Anon Mar 26 '14 at 17:18

You need to install the package

apt-get install iptables-persistent

in order to make your changes persistent.

In order to save your current settings use

/etc/init.d/iptables-persistent save

Next time you boot, the settings will be restored.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.