Security

How to save/restore and backup iptables rules

Netfilter - Linux firewallToday 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:

  1. 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_rules

    Restoring iptables rules

    [root@Ezylinux ~]# iptables-restore < /path/iptables_rules
  2. Commands for saving and restoring iptables rules. Saving iptables rules

    [root@Ezylinux ~]# /etc/init.d/iptables save

    Or:

    [root@Ezylinux ~]# /etc/init.d/iptables save

    After 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 start

    On Debian/Ubuntu, add:

    post-up iptables-restore

    to /etc/network/interfaces using this command:

    [root@Ezylinux ~]# vi /etc/network/interfaces
EOF.← Back to articles