如何在Centos 7上启用防火墙?

我的防火墙目前不活动。

systemctl status firewalld firewalld.service Loaded: masked (/dev/null) Active: inactive (dead) 

我使用以下命令来启用防火墙

 # systemctl unmask firewalld 

但是我得到这个错误:

 # systemctl unmask firewalld Failed to issue method call: Access denied # sudo systemctl restart firewalld Failed to issue method call: Unit firewalld.service failed to load: No such file or directory. # sudo systemctl enable firewalld Failed to issue method call: Access denied 

如果只是为了权限,那么也许你可以尝试

 sudo su systemctl enable firewalld systemctl start firewalld 

强烈build议您使用防火墙来保护您的服务器:

当您尝试启动或启用未安装在您的Linux系统上的服务或者键入错误的服务名称时,会出现此错误。 input以下内容查看服务列表:

 systemctl list-units --type=service 

如果不可用,请安装:

  yum install firewalld 

您可以键入以下命令来启用firewalld

 systemctl enable firewalld sudo systemctl enable firewalld 

你可以键入以下命令启动firewalld

 systemctl start firewalld sudo systemctl start firewalld 

看看通过键入以检查其状态:

 systemctl status firewalld 

另外,如果你想使用iptables而不是firewalld作为你select的防火墙,请参阅如何在RHEL 7和Fedora 18上启用iptables(而不是firewalld)服务? 其中包含有关如何为RHEL 7 / centos 7安装和启用iptables的确切说明。

我个人更喜欢旧的好的iptables用户空间接口。 所以:

最初禁用firewalld。 在你的情况下,这可能是没有必要的:

 systemctl disable firewalld 

然后安装iptables:

 yum install iptables-services 

启用iptables服务:

 systemctl enable iptables 

现在,您可以照常保存规则:

 service iptables save