Linux IPTables Rules Persistence

Use this systemd service to have /etc/iptables.rules reloaded on each reboot:

In /etc/systemd/system/iptables-restore.service:

Description=Iptables service

ExecStart=/sbin/iptables-restore -n /etc/iptables.rules


Run the following enable the service to run on boot:

sudo systemctl enable iptables-restore.service.

Saving IPTables Changes:

Run the following command to save your iptables rules to /etc/iptables.rules to be restored on each boot:

sudo iptables-save | sudo tee /etc/iptables.rules
Written on August 11, 2020