Linux command iptables can be used to make changes to Linux iptables. By default these changes are not reboot-safe and will get lost on reboot. Use these commands to save or restore iptables on Centos (Centos 6).
- Install iptables service if not installed using:
$ sudo yum install iptables $ sudo chkconfig iptables on $ sudo chkconfig ip6tables on
- To save changes made to iptables
$ sudo service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] $ sudo service ip6tables save $ sudo service ip6tables save ip6tables: Saving firewall rules to /etc/sysconfig/ip6table[ OK ]
- To save iptables changes to a temporary file and diff it with /etc/sysconfig/iptables. This may be useful to review what was changed before saving it.
$ sudo iptables-save > /tmp/current.iptables $ sudo diff /tmp/current.iptables /etc/sysconfig/iptables $ sudo ip6tables-save > /tmp/current.ip6tables $ sudo diff /tmp/current.ip6tables /etc/sysconfig/ip6tables
- To reload iptables data (this will undo any unsaved changes)
$ sudo service iptables restart $ sudo service ip6tables restart