How do I save iptables rules or settings?
Q. I am using GUI tool to setup rules for my home computer connected to ADSL (DSL/Cable) network. However after reboot my rules are not there. Is there any way I can save and load them again.
A. You need to use iptables-save command which is used to dump the contents of an IP Table in easily parseable format to screen. Using I/O-redirection provided by your shell you can save iptables firewall rules to a file.
Next time when you want to restore iptables rules use iptables-restore command. It is used to restore IP Tables from data specified from file. Use I/O redirection provided by your shell to read from a file.
Example
For example, save current iptables firewall rules:
# iptables-save > /root/dsl.fw
To restore iptables rules:
# iptables-restore < /root/dsl.fw
Redhat/Fedora core linux
To restore rules automatically upon Linux system reboot add following command to your /etc/rc.local (if you are using Fedora or Red Hat Linux):
# vi /etc/rc.local
Append the line:
iptables-restore < /root/dsl.fw
Save the file. Please note that under Red Hat enterprise Linux you can use following commands:
To Save the rules to /etc/sysconfig/iptables file:
# /etc/init.d/iptables save
To Restore the rules from /etc/sysconfig/iptables file:
# /etc/init.d/iptables start
If you are using Debian Linux open /etc/network/interfaces:
# vi /etc/network/interfaces
Append the line to eth0 section:
post-up iptables-restore
Close and save the file. Reboot the system.
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- Linux disable or remove the iptables firewall
- Howto disable the iptables firewall in Linux
- Iptables open ftp port 21
- Linux Firewall: Display Status and Rules of Iptables Firewall
- Linux passive ftp not working problem and solution
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!



March 6th, 2008 at 6:42 am
Thank you! This helped me out a lot.