CentOS 7 :Failed to start IPv4 firewall with iptables.

本文涉及的产品
云防火墙,500元 1000GB
简介: CentOS 7 :Failed to start IPv4 firewall with iptables.

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

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

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

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

停止并屏蔽firewalld:

1. systemctl stop firewalld
2. systemctl mask firewalld

安装iptables-services:

yum install iptables-services

设置开机启动:

systemctl enable iptables

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

1. systemctl [stop|start|restart] iptables
2. #or
3. service iptables [stop|start|restart]

保存防火墙配置:


1. service iptables save
2. #or
3. /usr/libexec/iptables/iptables.init save

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

二、从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



总结:

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

       抓住一个问题,深入去挖,往往能挖出一片,从而扫清一片盲点。深挖能出清泉。


参考文章:

https://www.vkilo.com/rhel-7-iptables-service.html

http://blog.csdn.net/Joe68227597/article/details/75207859

http://www.linuxidc.com/Linux/2012-06/63111.htm

http://man.linuxde.net/systemctl


相关文章
|
Linux
centos使用iptables实现nat端口转发
centos使用iptables实现nat端口转发
970 4
|
安全 Linux 网络安全
centos7中firewall防火墙的常用命令总结
以上命令集覆盖了 `firewalld`的基本操作,是维护CentOS 7系统安全不可或缺的工具。对于更高级的配置需求或遇到特定问题
264 3
|
安全 Linux 网络安全
百度搜索:蓝易云【服务器安全设置Centos7 防火墙firewall与iptables】
CentOS 7使用的默认防火墙是firewall,它是一种基于Netfilter的用户空间工具,用于管理Linux内核中的iptables规则。为了加强服务器的安全性,可以通过配置CentOS 7防火墙和iptables规则来保护服务器。
218 0
|
网络协议 Linux 网络安全
Centos7中如何打开和关闭防火墙??CentOS 7以上默认使用firewall作为防火墙改为iptables
Centos7中如何打开和关闭防火墙??CentOS 7以上默认使用firewall作为防火墙改为iptables
|
网络协议 Linux 网络安全
centos firewall 理解
centos firewall 理解
192 0
|
网络协议 Linux 网络安全
【Linux环境】centos7 Failed to start iptables.service: Unit not found 防火墙
【Linux环境】centos7 Failed to start iptables.service: Unit not found 防火墙
848 0
|
Shell Linux 开发工具
CentOS7安装oh-my-zsh(github start Top 10)
CentOS7安装oh-my-zsh(github start Top 10)
494 0
|
3月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
722 69
|
2月前
|
存储 分布式计算 Linux
安装篇--CentOS 7 虚拟机安装
VMware 装 CentOS 7 不知道从哪下手?这篇超详细图文教程手把手教你在 VMware Workstation 中完成 CentOS 7 桌面系统的完整安装流程。从 ISO 镜像下载、虚拟机配置,到安装图形界面、设置用户密码,每一步都有截图讲解,适合零基础新手快速上手。装好之后无论你是要搭 Hadoop 集群,还是练 Linux ,这个环境都够你折腾一整天!
870 2
|
3月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
335 78