当前位置:   article > 正文

service iptables save The service command supports only basic LSB actions

service iptables save the service command supports only basic lsb actions (s

执行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.

原因

从 CentOS 7.x 开始,CentOS 开始使用 systemd 服务来代替 daemon,原来管理系统启动和管理系统服务的相关命令全部由 systemctl 命令来代替。service 命令之保留了极少部分使用,大部分命令都要改用 systemctl 命令来使用。

在 RHEL 7 和 CentOS 7 中, firewalld 被引入来管理 iptables

解决方案

首先停止防火墙:

systemctl stop firewalld
systemctl mask firewalld
  • 1
  • 2

在 CentOS 7 和 RHEL 7 中,没有 /etc/sysconfig/iptables 这个配置文件,也不能执行 service iptables restart 命令,需要通过安装 iptables-services 才有。

# 查看当前系统版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@localhost ~]# rpm -qa|grep iptables
iptables-1.4.21-35.el7.x86_64
iptables-services-1.4.21-35.el7.x86_64
[root@localhost ~]# yum -y install iptables-services
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

然后就可以使用 service iptables [start | stop | restart | save …] 命令

# 这样就可以保存防火墙规则了
[root@test ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@test ~]# ll /etc/sysconfig/iptables
-rw-------. 1 root root 6479 Nov  7 04:00 /etc/sysconfig/iptables

# 或者 使用如下命令
[root@test ~]# /usr/libexec/iptables/iptables.init save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

添加端口

# 添加9000
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 9000 -j ACCEPT
# 保存规则
service iptables save
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/888643
推荐阅读
相关标签
  

闽ICP备14008679号