CentOS 7.2:Failed to start IPv4 firewall with iptables

这个问题整了我一天,真心没有感觉firewall有哪里好用了,除了麻烦还是麻烦,就像直接卸载掉,但是貌似不能卸载,只能禁用了,禁用后iptable也么有法用,直接报错:

● iptables.service - IPv4 firewall with iptables
   Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-07-03 21:38:16 CST; 53s ago
  Process: 3813 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=1/FAILURE)
 Main PID: 3813 (code=exited, status=1/FAILURE)


Jul 03 21:38:16 localhost.localdomain systemd[1]: Starting IPv4 firewall with iptables...
Jul 03 21:38:16 localhost.localdomain iptables.init[3813]: iptables: Applying firewall rules: iptables-restore: line 2 failed
Jul 03 21:38:16 localhost.localdomain iptables.init[3813]: [FAILED]
Jul 03 21:38:16 localhost.localdomain systemd[1]: iptables.service: main process exited, code=exited, status=1/FAILURE
Jul 03 21:38:16 localhost.localdomain systemd[1]: Failed to start IPv4 firewall with iptables.
Jul 03 21:38:16 localhost.localdomain systemd[1]: Unit iptables.service entered failed state.
Jul 03 21:38:16 localhost.localdomain systemd[1]: iptables.service failed.

现在用下面的命令正好可以完美解决这个问题,

启动命令如下:

systemctl start iptables.service

报错如下:

Job for iptables.service failed because the control process exited with error code. See "systemctl status iptables.service" and "journalctl -xe" for details.

两台服务器都是同样的环境,但是一台一切正常,另一台却是这种情况,觉得有点不对劲,之后尝试了几种其他方式,也试过重装iptables服务和重启服务器的方式,但是依然会报这个错误。

执行journalctl -xe查看错误日志,查到了更加具体的原因,错误如下:

Failed to start IPv4 firewall with iptables.

到这里大概知道问题的原因了。

解决办法

因为centos7默认的防火墙是firewalld防火墙,不是使用iptables,因此需要先关闭firewalld服务,或者干脆使用默认的firewalld防火墙。

因为这次报错的服务器是一台刚刚购买的阿里云服务器,所以在操作上忘记关闭默认防火墙的步骤了才导致浪费了些时间在这件事情上。

关闭firewalld:

systemctl stop firewalld  
systemctl mask firewalld

使用iptables服务:

#开放443端口(HTTPS)
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

#保存上述规则
service iptables save

#开启服务
systemctl restart iptables.service

一切正常。

还是挺想直接卸载掉filewall。。。。。

我曾七次鄙视自己的灵魂:
第一次,当它本可进取时,却故作谦卑;
第二次,当它空虚时,用爱欲来填充;
第三次,在困难和容易之间,它选择了容易;
第四次,它犯了错,却借由别人也会犯错来宽慰自己;
第五次,它自由软弱,却把它认为是生命的坚韧;
第六次,当它鄙夷一张丑恶的嘴脸时,却不知那正是自己面具中的一副;
第七次,它侧身于生活的污泥中虽不甘心,却又畏首畏尾。

猜你喜欢

转载自blog.csdn.net/com_ma/article/details/80904818
今日推荐