Answer the question
In order to leave comments, you need to log in
How to keep iptables rules after Ubuntu reboot?
After rebooting Ubuntu 12.10, the iptables rules "fly off". I know that it is possible to win by prescribing rules in rc.local. As an alternative, it was advised to use ferm. What does an experienced Khabrovchanin think about this topic? Which option is preferable and where can there be “pitfalls”?
Answer the question
In order to leave comments, you need to log in
Here is a solution that works for Debian 6.0 and Debian 7.0 for now, should work on Ubuntu as well.
Under superuser:
nano -w /etc/network/if-up.d/00-iptables
#!/bin/sh
iptables-restore < /etc/firewall.conf
ip6tables-restore < /etc/firewall6.conf
chmod +x nano -w /etc/network/if-up.d/00-iptables
iptables-save >/etc/firewall.conf
ip6tables-save >/etc/firewall6.conf
debian and ubuntu added iptables-persistent package
which uses iptables-save/iptables-restore
#service iptables-persistent
Usage: /etc/init.d/iptables-persistent {start|restart|reload|force-reload|save|flush}
after configuring the rules as needed, do a service iptables-persistent save and they will be applied on the next boot
If you do not use a network manager to raise the network, then you can write to the end of /etc/network/interfaces
post-up iptables-restore < /etc/iptables.rules
After applying the rules and saving them to this same iptables.rules file with the command$ iptables-save > /etc/iptables.rules
IMHO it's much better to have a bash/sh file that creates rules at autoload than to use iptables-save and iptables-restore.
After all, in a bash file you cannot replace the same addresses/ports/interfaces/protocols/ranges in different lines with variables, you can, if you wish, set up some kind of loop or enable routing in /proc/sys/net/ipv4/ip_forward ( it is more logical to combine it with the rules, because without it they may not make sense)
Just like in Debian. It means that they are the same by default in this regard.
Win - by creating a file with the rules and adding it to rc.local for execution, or better - to autoload by putting the file in init.d.
Once on the command line:
iptables-save > /etc/network/iptables.save
In /etc/rc.local:
F="/etc/network/iptables.save"
test -f "$F" && /sbin/iptables-restore < $F
Alt and ASP use an entry in /etc/sysconfig/iptables; default recovery is specified when the network service is brought up.
It is best to entrust the management of iptables rules to some firewall builder. He will restore everything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question