防火墙重启失败 Failed to start IPv4 firewall with iptables.

转载:https://blog.csdn.net/ls1645/article/details/78750561

防火墙重启失败。Failed to start IPv4 firewall with iptables.

service iptables restart 开启防火墙报错: Failed to start  IPv4 firewall with iptables.

    错误原因:因为centos7.0默认不是使用iptables方式管理,而是firewalld方式。CentOS6.0防火墙用iptables管理。

        解决办法有两个:使用firewalld方式。或者关闭firewalld,然后安装iptables。

一、关闭firewalld,安装iptables过程:

停止并屏蔽firewalld:

[ruby]  view plain  copy
  1. systemctl stop firewalld  
  2. systemctl mask firewalld  

安装iptables-services:

[ruby]  view plain  copy
  1. yum install iptables-services  

设置开机启动:

[ruby]  view plain  copy
  1. systemctl enable iptables  

停止/启动/重启 防火墙:

[ruby]  view plain  copy
  1. systemctl [stop|start|restart] iptables  
  2. #or  
  3. service iptables [stop|start|restart]  

     按照上述命令配置后的界面:

二、从iptables切换回firewalld

    1、先看firewalld的状态:inactive

     

    2、安装firewalld

   3、切换到firewalld,切换过程与切换iptables一样


/************下面是iptables的一些命令*******************************/

查询防火墙状态:

[root@localhost ~]# service  iptables status

停止防火墙:

[root@localhost ~]# service  iptables stop 

启动防火墙:

[root@localhost ~]# service  iptables start 

重启防火墙:

[root@localhost ~]# service  iptables restart 

永久关闭防火墙:

[root@localhost ~]# chkconfig  iptables off 

永久关闭后启用:

[root@localhost ~]# chkconfig  iptables on

开启端口:

[root@localhost ~]# vim/etc/sysconfig/iptables


/**********下面是firewalld的一些命令*****************************/

#systemctl statusfirewalld  //查看状态,看电脑上是否已经安装firewalld

#yum installfirewalld  //安装firewalld防火墙

#systemctl startfirewalld.service   //开启防火墙

#systemctl stop firewalld.service  //关闭防火墙

#systemctl enable firewalld.service //设置开机自动启动

#systemctl disable firewalld.service  //设置关闭开机制动启动

#firewall-cmd--reload  //在不改变状态的条件下重新加载防火墙

启用某个服务

#firewall-cmd --zone=public --add-service=https  //临时

#firewall-cmd --permanent --zone=public --add-service=https  //永久

开启某个端口

#firewall-cmd--permanent --zone=public --add-port=8080-8081/tcp  //永久

#firewall-cmd  --zone=public --add-port=8080-8081/tcp   //临时

查看开启的端口和服务

#firewall-cmd--permanent --zone=public --list-services   //服务空格隔开 例如 dhcpv6-client https ss  

#firewall-cmd--permanent --zone=public --list-ports //端口空格隔开  例如 8080-8081/tcp 8388/tcp 80/tcp

#systemctl restartfirewalld.service  //修改配置后需要重启服务使其生效

#firewall-cmd--zone=public --query-port=8080/tcp //查看服务是否生效(例:添加的端口为8080)


/**********下面是systemctl的一些命令*******************************/

        观察iptables和firewalld使用的两组命令,发现三个常用的命令:service、chkconfig、systemctl。那么它们分别是做什么的呢?(去网上搜索了一下给出了答案)

        systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

任务

旧指令

新指令

使某服务自动启动

chkconfig --level 3 httpd on

systemctl enable httpd.service

使某服务不自动启动

chkconfig --level 3 httpd off

systemctl disable httpd.service

检查服务状态

service httpd status

systemctl status httpd.service(服务详细信息) 

systemctl is-active httpd.service(仅显示是否 Active)

显示所有已启动的服务

chkconfig --list

systemctl list-units --type=service

启动某服务

service httpd start

systemctl start httpd.service

停止某服务

service httpd stop

systemctl stop httpd.service

重启某服务

service httpd restart

systemctl restart httpd.service

总结:

        记是记不住的,实操才可以,熟能生巧。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
这个错误通常是由于iptables配置文件中存在错误或者iptables服务未正确安装导致的。你可以尝试运行以下命令来检查iptables服务是否已正确安装: ``` sudo systemctl status iptables ``` 如果该命令返回“Unit iptables.service could not be found”或者“iptables.service loaded failed”,则说明iptables服务未正确安装。你可以使用以下命令来安装iptables服务: ``` sudo yum install iptables-services ``` 安装完成后,你可以使用以下命令来启动iptables服务: ``` sudo systemctl start iptables ``` 如果该命令返回“Failed to start iptables.service: Unit iptables.service not found”错误,则你需要手动创建iptables.service文件。你可以使用文本编辑器打开/etc/systemd/system/iptables.service文件,并将以下内容复制到文件中: ``` [Unit] Description=IPv4 firewall with iptables After=syslog.target network.target [Service] Type=oneshot ExecStart=/usr/libexec/iptables/iptables.init start ExecStop=/usr/libexec/iptables/iptables.init stop [Install] WantedBy=multi-user.target ``` 保存文件后,使用以下命令来重新加载systemd服务并启动iptables服务: ``` sudo systemctl daemon-reload sudo systemctl start iptables ``` 如果iptables服务启动仍然失败,请尝试查看系统日志以获取更多信息: ``` sudo tail /var/log/messages ``` 该命令将显示iptables服务启动失败的详细信息,你可以根据提示进行进一步的排查。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值