iptables: rules lost after reboot
Fix iptables rules disappearing after a system reboot by saving them to a persistent configuration file.
iptables: rules lost after reboot
iptables rules disappear after a system reboot because they are stored in memory and not saved to a persistent configuration file.
When iptables Produces This Error
After rebooting the server,
iptables -L shows an empty ruleset or only default ACCEPT policies. All custom rules — port openings, NAT, rate limits — are gone.
What Causes iptables Rules to Be Lost After Reboot
iptables stores rules in kernel memory. When the system reboots, the kernel reinitializes and the rules are cleared. Unlike nftables (which reads
/etc/nftables.conf at boot), iptables has no built-in persistence mechanism.
How to Fix iptables Rules Lost After Reboot
Install
iptables-persistenton Ubuntu/Debian:sudo apt install iptables-persistentSave the current rules:
sudo iptables-save | sudo tee /etc/iptables/rules.v4Verify the rules load on boot by rebooting and checking:
sudo reboot # After reboot: sudo iptables -L -n
How to Verify the Fix
After reboot,
iptables -L -n should display the saved rules.