Keep iptables rules after a reboot on CentOS
Why your firewall rules disappear after a restart on CentOS, and the settings that keep them.
From the archive: first published on mohamedsharaf.net in August 2018. Rewritten and checked in 2026; some details may be out of date.
A classic surprise: you add firewall rules with iptables, everything works, the server reboots, and the rules are gone. They only lived in memory.
On CentOS 6 and 7 (with the iptables-services package), tell the service to save the rules when it stops or restarts, in /etc/sysconfig/iptables-config:
IPTABLES_SAVE_ON_STOP="yes"
IPTABLES_SAVE_ON_RESTART="yes"
Then save the current rules and make sure the service starts at boot:
service iptables save
chkconfig iptables on # CentOS 6
systemctl enable iptables # CentOS 7
Today: newer distributions use firewalld or nftables, where you make rules permanent with firewall-cmd --permanent or by saving the nftables ruleset. Whatever the tool, test a reboot before you trust it.