CentOS 7.2 (mini) 里iptables防火墙怎么关闭?

[root@localhost init.d]# service iptables stop
Redirecting to /bin/systemctl stop  iptables.service
Failed to stop iptables.service: Unit iptables.service not loaded.
[root@localhost init.d]# iptables stop
Bad argument `stop'
Try `iptables -h' or 'iptables --help' for more information.
[root@localhost init.d]# service firewall stop
Redirecting to /bin/systemctl stop  firewall.service
Failed to stop firewall.service: Unit firewall.service not loaded.
[root@localhost init.d]# firewall stop
-bash: firewall: 未找到命令
[root@localhost init.d]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 
[root@localhost init.d]# systemctl enable iptables
Failed to execute operation: Access denied
[root@localhost init.d]# systemctl stop iptables
Failed to stop iptables.service: Unit iptables.service not loaded.
[root@localhost init.d]# /usr/libexec/iptables/iptables.init save
-bash: /usr/libexec/iptables/iptables.init: 没有那个文件或目录
[root@localhost init.d]# 

请看下上面几条命令和结果,证明安装了iptables,但是Unit iptables.service not loaded.
该怎么办?

阅读 52.1k
4 个回答

centos从7开始默认用的是firewalld,这个是基于iptables的,虽然有iptables的核心,但是iptables的服务是没安装的。所以你只要停止firewalld服务即可:
sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service

如果你要改用iptables的话,需要安装iptables服务:
sudo yum install iptables-services
sudo systemctl enable iptables && sudo systemctl enable ip6tables
sudo systemctl start iptables && sudo systemctl start ip6tables

Redirecting to /bin/systemctl stop iptables.service

systemctl stop iptables.service

正确答案出现了。
首先系统是CentOS-7-x86_64-Minimal-1511
运行firewall防火墙但是这个好像有点问题看下面代码。
然后这不是外网不能访问虚拟服务器原因,测试代码python -m SimpleHTTPServer 8080后发现可以访问。
得出结果 虚拟服务器设定服务ip不能是127.0.0.1而是0.0.0.0。

[root@localhost flaskapp]# systemctl start firewalld.service
Failed to start firewalld.service: Unit firewalld.service is masked.
[root@localhost flaskapp]# firewall-cmd --state
running
[root@localhost flaskapp]# systemctl status firewalld.service
● firewalld.service
   Loaded: masked (/dev/null)
   Active: failed (Result: timeout) since Thu 2015-12-24 06:56:31 PST; 9h ago
 Main PID: 6554 (code=exited, status=0/SUCCESS)

Dec 24 06:56:31 localhost.localdomain systemd[1]: firewalld.service start operation timed out. Terminating.
Dec 24 06:56:31 localhost.localdomain systemd[1]: Failed to start firewalld - dynamic firewall daemon.
Dec 24 06:56:31 localhost.localdomain systemd[1]: Unit firewalld.service entered failed state.
Dec 24 06:56:31 localhost.localdomain systemd[1]: firewalld.service failed.
Dec 24 07:02:11 localhost.localdomain systemd[1]: Cannot add dependency job for unit firewalld.service, ignoring: Unit firewalld.service is masked.
Dec 24 12:26:16 localhost.localdomain systemd[1]: Stopped firewalld.service.
Dec 24 12:28:14 localhost.localdomain systemd[1]: Stopped firewalld.service.
Dec 24 12:29:07 localhost.localdomain systemd[1]: Stopped firewalld.service.
Dec 24 12:45:11 localhost.localdomain systemd[1]: Stopped firewalld.service.
Dec 24 16:29:41 localhost.localdomain systemd[1]: Stopped firewalld.service.

yum install iptables-services

宣传栏