How to persist firewall rules across reboots

Save iptables and nftables rules so they survive reboots using iptables-persistent or systemd services.

How to persist firewall rules across reboots

Save iptables and nftables rules so they survive reboots using iptables-persistent or systemd services.

Prerequisites

  • Root access on a Linux system with iptables or nftables.

Step-by-Step: Persist iptables Rules on Ubuntu/Debian

  1. Install the iptables-persistent package. It saves current rules during installation:

    sudo apt install iptables-persistent
  2. Save rules manually after making changes:

    sudo iptables-save | sudo tee /etc/iptables/rules.v4
    sudo ip6tables-save | sudo tee /etc/iptables/rules.v6
  3. Rules load automatically at boot via the netfilter-persistent systemd service.

Step-by-Step: Persist nftables Rules

  1. Save the current nftables ruleset to the configuration file:

    sudo nft list ruleset | sudo tee /etc/nftables.conf
  2. Enable the nftables service to load rules at boot:

    sudo systemctl enable nftables