15

I have a Redhat server (Red Hat Enterprise Linux Server release 7.2 (Maipo)) that resets iptable rules on re/boot.

According to the version 6 documentation, I execute:

/sbin/service iptables save

which returns:

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.

If I understand the message correctly, I attempted the following:

sudo systemctl iptables save

which returns:

Unknown operation 'iptables'.

I cannot locate the version 7 documentation on saving ip tables specifically, but previous versions support the same command.

What command should I run to save iptables config?

For reference:

firewall d satatus:

systemctl status firewalld
firewalld.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
1

2 Answers 2

23

You should install iptables-services package.

Then service iptables save will work. Also these commands will work too:

# iptables-save > /etc/sysconfig/iptables
# ip6tables-save > /etc/sysconfig/ip6tables

AFAIK, systemctl doesn't have any option to save iptables-services' configuration.

Note: systemctl syntax is as follow : systemctl <operation> <unit>

2
  • By the way, i do not recommend above ways if the rule changes are permanent. I choose to keep comments about rules in /etc/sysconfig/iptables file that system administrators should do in order to provide information for future administrators or just a reminder. If you save the configuration with above commands, comments will be lost. Simply use a text editor to edit the file and reload the service with systemctl.
    – Aesnak
    Commented Sep 6, 2016 at 14:48
  • It's annoying that there is not consistency in this area by know. systemctl save iptables, should be a thing. Commented Nov 14, 2022 at 13:41
1

Here is link to Security Guide for Red Hat 7: using_firewalls

I use

# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)

And status of firewalld service:

# systemctl status firewalld
Active: active (running) since Fri 2018-04-13 10:00:18 CEST; 31min ago

So I think, you could also enable firewalld service:

systemctl start firewalld
systemctl enable firewalld

And change rules via firewall-config

  1. Press Super
  2. Type firewall,
  3. Select Permanent in drop down menu
  4. Put necessary settings
1
  • the question is about iptables, not firewalld
    – None
    Commented Nov 30, 2021 at 2:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .