[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.
该怎么办?
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