How to save/restore and backup iptables rules
Today I will cover a simple topic for anyone unfamiliar with the commands for saving, backing up, and restoring iptables rules. This article does not cover the iptables GUI.
One problem with Linux iptables is that if we restart the machine without saving the rules, they disappear after boot. Knowing the save command lets us reload the same rules after a restart. I will also cover commands for backing up and restoring iptables rules, and using the backup file on another machine. There are two forms of use:
-
Commands for backing up and restoring iptables rules: iptables-save and iptables-restore. Here is how to use them. Backing up iptables rules
[root@Ezylinux ~]# iptables-save > /path/iptables_rulesRestoring iptables rules
[root@Ezylinux ~]# iptables-restore < /path/iptables_rules -
Commands for saving and restoring iptables rules. Saving iptables rules
[root@Ezylinux ~]# /etc/init.d/iptables saveOr:
[root@Ezylinux ~]# /etc/init.d/iptables saveAfter running the save command, the file is stored at /etc/sysconfig/iptables. Restoring iptables rules On Red Hat/CentOS/SuSe, use:
[root@Ezylinux ~]# /etc/init.d/iptables startOn Debian/Ubuntu, add:
post-up iptables-restoreto /etc/network/interfaces using this command:
[root@Ezylinux ~]# vi /etc/network/interfaces