Linux:Failed to start iptables.service: Unit iptables.service not found.

出现的问题

虚拟机:centos
想使用

service iptables start

这个命令打开防火墙,然后出现了如下的提示
在这里插入图片描述

Failed to start iptables.service: Unit iptables.service not found.
即找不到iptables.service这个服务


怎么解决

第一,我们要知道centos7.0之前使用service这个命令管理服务,centos7.0之后使用systemctl命令管理服务程序,也就是说解决方式1是换个命令
第二,可以下载iptables-services。

格式分别如下:

service 服务名【start/stop/restart/reload/status】


systemctl 【start/stop/restart/reload/status】服务名

1. 使用systemctl命令

在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理

添加

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

(–permanent表示永久生效,没有此参数重启后会失效)

添加范围例外端口 如 1000-2000:

firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent

重新载入

firewall-cmd --reload

查看

firewall-cmd --zone=public --query-port=80/tcp

删除

firewall-cmd --zone=public --remove-port=80/tcp --permanent

开启防火墙

systemctl start firewalld.service

//或者省略firewalld.service后面的.service也可以,下面一条命令也一样。
关闭防火墙

systemctl stop firewalld.service

查看运行状态

firewall-cmd --state 

//running 表示运行


补充下面一种情况

systemctl 启动 firewalld 时出现 Failed to start firewalld.service: Unit is masked.
//这说明这里命令被锁定住了,你不能进行start或者stop等其他的操作,想要操作就必须先解锁

锁定服务命令

systemctl mask firewalld

会出现如下提示

Created symlink /etc/systemd/system/firewalld.service → /dev/null.

解除锁定

systemctl unmask firewalld

出现如下提示

Removed /etc/systemd/system/firewalld.service.

2. 继续使用service

首先安装iptables-services

yum install iptables-services

但如若是centos7及以上版本的会显示如下的信息
在这里插入图片描述
让你使用systemctl命令,而不是继续用service命令(妈了个巴子,搞来搞去还是用systemctl命令)

systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables

此时就把问题解决了,机智如我。。。哈哈哈哈(仰天长笑)


感谢阅读。。。有错请指出,一起努力进步。。。

猜你喜欢

转载自blog.csdn.net/lalala_dxf/article/details/120581863
今日推荐