1. 程式人生 > >解決 service iptables save 報錯 please try to use systemctl

解決 service iptables save 報錯 please try to use systemctl

本文件根據 service iptables save 報錯 please try to use systemctl 提供解決方案。

報錯

[root@Jaking ~]# 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.

解決方法

停止 firewalld

[root@Jaking ~]# systemctl stop firewalld
[root@Jaking ~]# systemctl mask firewalld
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.

安裝 iptables-services

[root@Jaking ~]# yum install -y iptables-services

開啟 iptables

[root@Jaking ~]# service iptables start
Redirecting to /bin/systemctl start iptables.service

還可以使用 systemctl 來控制 iptables

systemctl [start|status|stop|restart|enable] iptables

把 iptables 加到開機啟動項中

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

清空防火牆

[root@Jaking ~]# iptables -F

儲存防火牆規則

[root@Jaking ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]
# 或者
[root@Jaking ~]# /usr/libexec/iptables/iptables.init save
iptables: Saving firewall rules to /etc/sysconfig