经常start、stop、restart操作防火墙有两种方式:

1、service iptables stop

2、/etc/init.d/iptables stop

  但是经常会有这种错误,因为在RHEL7、CentOS种其实没有这个服务。

[root@rhel7 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)
[root@rhel7 ~]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service
[root@rhel7 ~]# /etc/init.d/iptables stop
-bash: /etc/init.d/iptables: No such file or directory

  或者

[root@CTU1000094955 ~]#  cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@CTU1000094955 ~]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service
Failed to stop iptables.service: Unit iptables.service not loaded.
[root@CTU1000094955 ~]# /etc/init.d/iptables stop
-bash: /etc/init.d/iptables: No such file or directory

  原来在RHEL7、CentOS7开始,使用systemctl工具来管理服务程序,包括了service和chkconfig。

[root@CTU1000094955 ~]# systemctl list-unit-files|grep firewall
firewalld.service disabled

  那么systemctl管理防火墙:

启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $?
查看已启动的服务列表:systemctl list-unit-files|grep enabled

示例:

1、关闭防火墙并查看运行状态

[root@CTU1000094955 ~]# systemctl stop firewalld.service
[root@CTU1000094955 ~]# systemctl list-unit-files |grep firewall
firewalld.service disabled
[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
FirewallD is not running
[root@CTU1000094955 ~]# systemctl status firewalld.service
?.firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead) Nov :: CTU1000094955 systemd[]: Starting firewalld - dynamic firewall daemon...
Nov :: CTU1000094955 systemd[]: Started firewalld - dynamic firewall daemon.
Nov :: CTU1000094955 systemd[]: Started firewalld - dynamic firewall daemon.
Nov :: CTU1000094955 systemd[]: Stopping firewalld - dynamic firewall daemon...
Nov :: CTU1000094955 systemd[]: Stopped firewalld - dynamic firewall daemon.

2、开启防火墙并查看防护墙状态

[root@CTU1000094955 ~]# systemctl start firewalld.service
[root@CTU1000094955 ~]# systemctl status firewalld.service
?.firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Sat -- :: CST; 5s ago
Main PID: (firewalld)
CGroup: /system.slice/firewalld.service
?.. /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid Nov :: CTU1000094955 systemd[]: Starting firewalld - dynamic firewall daemon...
Nov :: CTU1000094955 systemd[]: Started firewalld - dynamic firewall daemon.
[root@CTU1000094955 ~]# systemctl list-unit-files |grep firewall
firewalld.service disabled
[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
/tcp /tcp

  与此同时,还可以通过firewall -cmd来操作防火墙

[root@CTU1000094955 ~]# man firewall-cmd
FIREWALL-CMD() firewall-cmd FIREWALL-CMD() NAME
firewall-cmd - firewalld command line client SYNOPSIS
firewall-cmd [OPTIONS...] DESCRIPTION
firewall-cmd is the command line client of the firewalld daemon. It provides interface to manage runtime and permanent configuration. The runtime configuration in firewalld is separated from the permanent configuration. This means that things can get changed in the runtime or permanent configuration. OPTIONS
The following options are supported: General Options
-h, --help
Prints a short help text and exits. -V, --version
Print the version string of firewalld. This option is not combinable with other options. -q, --quiet
Do not print status messages. Status Options
--state
Check whether the firewalld daemon is active (i.e. running). Returns an exit code if it is active, NOT_RUNNING otherwise (see the section called ?.XIT CODES?.. This will
also print the state to STDOUT. --reload
Reload firewall rules and keep state information. Current permanent configuration will become new runtime configuration, i.e. all runtime only changes done until reload are
lost with reload if they have not been also in permanent configuration. --complete-reload

3、查看防火墙是否运行

[root@CTU1000094955 ~]# firewall-cmd --state
running

4、查看默认通过防火墙

[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
/tcp /tcp

  刚才测试添加了10001、80两个端口,参数--permanent 是永久配置机子重启依然有效。

5、删除默认通过防火墙的端口

[root@CTU1000094955 ~]# firewall-cmd --permanent --remove-port=/tcp
success
[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
/tcp

  可以看到刚刚能通过防火墙的80端口现在已经查不到了。

6、添加端口到防火墙例外

[root@CTU1000094955 ~]# firewall-cmd --permanent --zone=public --add-port=/tcp
success
[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
/tcp /tcp

  现在80端口又回来了。

RHEL7、CentOS7防火墙管理的更多相关文章

  1. 【RHEL7/CentOS7防火墙之firewall-cmd命令详解】

    目录 Firewalld zone firewall-cmd 开始配置防火墙策略 总结 Redhat Enterprise Linux7已默认使用firewalld防火墙,其管理工具是firewall ...

  2. centos7防火墙管理的变化

    当我们在centos7中输入service iptables status 查看系统的防火墙状态,会出现如下错误: 网上查阅才知道centos7的防火墙管理工具变了,原来的iptables已经不用了, ...

  3. CentOS7防火墙管理firewalld

    学习apache安装的时候需要打开80端口,由于centos 7版本以后默认使用firewalld后,网上关于iptables的设置方法已经不管用了,想着反正iptable也不太熟悉,索性直接搬官方文 ...

  4. Django Linux环境下部署CentOS7+Python3+Django+uWSGI+Nginx(含Nginx返回400问题处理、防火墙管理)

    本文将介绍如何在Linux系统上部署Django web项目,本次部署基于下面的架构: CentOS7+ Python3.5 + Django1.11 + uWSGI + Nginx 亲测可行!!按照 ...

  5. RHEL7 CentOS7 检查查看精简指令

    RHEL7 CentOS7 检查查看精简指令: //////////////////////////检查查看精简指令://///////////////////////////// ///////// ...

  6. Centos7防火墙快速开放端口配置方法

    ▲这篇文章主要为大家详细介绍了Centos7防火墙开放端口的快速方法,感兴趣的小伙伴们可以参考一下! Firewalld服务是红帽RHEL7系统中默认的防火墙管理工具,特点是拥有运行时配置与永久配置选 ...

  7. linux入门系列10--firewalld防火墙管理

    上一篇文章学习了用户及文件相关权限,本篇继续学习防火墙技术. 防火墙作为公网与内网之间的保护屏障,对系统至关重要.防火墙又分为硬件防火墙和软件防火墙,主要功能都是依据设置的策略对穿越防火墙的流量进行过 ...

  8. CentOS7 防火墙(firewall)的操作命令

    CentOS7 防火墙(firewall)的操作命令 安装:yum install firewalld 1.firewalld的基本使用 启动: systemctl start firewalld 查 ...

  9. CentOS7 防火墙配置firewall-cmd

    firewalld(Dynamic Firewall Manager of Linux systems,Linux系统的动态防火墙管理器)服务是默认的防火墙配置管理工具. firewall-cmd 是 ...

随机推荐

  1. hadoop-2

    AsyncDispatcher,直接看代码 @Override protected void serviceStart() throws Exception { //start all the com ...

  2. postman 请求种添加用户权限

    1. 打开postman, 在Tests输入以下内容: var jsonData =JSON.parse(responseBody);//获取body中返回的所有参数 postman.setGloba ...

  3. 关于maven中的快照版本(snapshot)与正式版本(release)解析。

    Maven中建立的依赖管理方式基本已成为Java语言依赖管理的事实标准,Maven的替代者Gradle也基本沿用了Maven的依赖管理机制.在Maven依赖管理中,唯一标识一个依赖项是由该依赖项的三个 ...

  4. XAMPP+composer+laravel+thinkphp5那些深情的往事

    xampp 依赖库 https://www.microsoft.com/zh-CN/download/details.aspx?id=29 下载地址 https://www.apachefriends ...

  5. 删除oracle数据库用户

    手工删除ORACLE数据库用户时常会出现会话进程仍在使用导致删除失败的情况.需要查询会话并将会话删除才能成功将数据库用户删除,比较不方便. 适用场景 自动删除oracle数据库用户 基本知识 orac ...

  6. webpack打包avalon+oniui+jquery

    随着avalon的发展壮大,我根据CSDN的统计数字,中国前端大概有1%的人在使用avalon了. avalon的最大优势是能兼容IE6,并且其API是非常稳定,只是在1.3.7 对ms-duplex ...

  7. openwrt用WEB刷固件型号不对问题强行处理

    参照这里:https://blog.csdn.net/caoshunxin01/article/details/79355602 原机是一块mt7620A的通板,之前刷了一个叫WE826型号的固件,发 ...

  8. 传输层——UDP报文头介绍

    16位源端口 16位目的端口 16位总长度 16位校验和 数据 源端口:长度为16位,2个字节. 目的端口:长度为16位,2个字节. 总长度:长度为16位,2个字节,表示 UDP包头长度 和 数据长度 ...

  9. 修改maven项目的编译版本

    在pom.xml中添加如下代码 <build> <!-- 配置了很多插件 --> <plugins> <plugin> <groupId>o ...

  10. python基础学习Day14 内置函数 匿名函数

    一.内置函数里几个高频重要函数 (1)min\max函数的用法 以min函数的为例: min:返回可迭代对象的最小值(可加key,key为函数名,通过函数的规则,返回最小值). l1 =[(,),(, ...