How to fix error can’t save iptables settings on CentOS 7


On CentOS 7, you can’t save iptables settings, how to fix this issue

[root@tutorialspots ~]# service iptables save
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
[root@tutorialspots ~]# systemctl save iptables
Unknown operation 'save'.

Step 1: check service firewalld:

[root@tutorialspots ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

If this service is running, disable it

systemctl disable firewalld

Step 2: install iptables-service

yum install iptables-services

Result:

[root@tutorialspots ~]# yum install iptables-services
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.us.oneandone.net
 * epel: fedora-epel.mirror.lstn.net
 * extras: mirror.fileplanet.com
 * ius: dfw.mirror.rackspace.com
 * nux-dextop: mirror.li.nux.ro
 * remi-safe: repo1.dal.innoscale.net
 * updates: repos.dfw.quadranet.com
Resolving Dependencies
--> Running transaction check
---> Package iptables-services.x86_64 0:1.4.21-28.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch          Version               Repository   Size
================================================================================
Installing:
 iptables-services        x86_64        1.4.21-28.el7         base         52 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 52 k
Installed size: 26 k
Is this ok [y/d/N]: y
Downloading packages:
iptables-services-1.4.21-28.el7.x86_64.rpm                 |  52 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : iptables-services-1.4.21-28.el7.x86_64                       1/1
  Verifying  : iptables-services-1.4.21-28.el7.x86_64                       1/1

Installed:
  iptables-services.x86_64 0:1.4.21-28.el7

Complete!

Step 3:

systemctl enable iptables
service iptables start

Result:

[root@tutorialspots ~]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@tutorialspots ~]# service iptables start
Redirecting to /bin/systemctl start iptables.service

Done, now you can save iptables settings:

[root@tutorialspots ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

Leave a Reply