Centos 7 save iptables settings

Solution 1:

Disable firewalld by the following command:

systemctl disable firewalld

Then install iptables-service by following command:

yum install iptables-services

Then enable iptables as services:

systemctl enable iptables

Now you can save your iptable rules by following command:

service iptables save

Solution 2:

CentOS 7 is using FirewallD now! Use the --permanent flag to save settings.

Example:

firewall-cmd --zone=public --add-port=3000/tcp --permanent

Then reload rules:

firewall-cmd --reload

Solution 3:

On CentOS 7 Minimal you may need to install the iptables-services package (thanks to @RichieACC for the suggestion):

sudo yum install -y iptables-services

And then enable the service using systemd:

sudo systemctl enable iptables.service

And run the initscript to save your firewall rules:

sudo /usr/libexec/iptables/iptables.init save

Solution 4:

iptables-save > /etc/sysconfig/iptables

will save the current configuration without the need to install any other libraries or services.


Solution 5:

You can modify directly the /etc/sysconfig/iptables file. Reload the iptables service to reload the rules from that file. Yet, as you were told already, firewalld is the new default firewall system for Centos, and this is a good chance to learn how to use it, don't you think?