CentOS7中firewalld的安装与使用详解

2023-05-16

一、软件环境

[root@Geeklp201 ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

二、安装firewalld

1、firewalld提供了支持网络/防火墙区域(zone)定义网络链接以及接口安全等级的动态防火墙管理工具。它支持 IPv4, IPv6 防火墙设置以及以太网桥接,并且拥有运行时配置和永久配置选项。它也支持允许服务或者应用程序直接添加防火墙规则的接口。firewall daemon 动态管理防火墙,不需要重启整个防火墙便可应用更改。因而也就没有必要重载所有内核防火墙模块了。不过,要使用 firewall daemon 就要求防火墙的所有变更都要通过该守护进程来实现,以确保守护进程中的状态和内核里的防火墙是一致的。另外,firewall daemon 无法解析由 ip*tables 和 ebtables 命令行工具添加的防火墙规则。守护进程通过 D-BUS 提供当前激活的防火墙设置信息,也通过 D-BUS 接受使用 PolicyKit 认证方式做的更改。

检查系统是否已经安装了firewalld和firewall-config。

[root@Geeklp201 ~]# rpm -qa|grep firewalld;rpm -qa|grep firewall-config
firewalld-filesystem-0.4.4.4-6.el7.noarch
firewalld-0.4.4.4-6.el7.noarch
firewall-config-0.4.4.4-6.el7.noarch
2、在CentOS7.4中,系统已经默认安装了firewalld,我们只需要安装firewall-config(注意:这里是firewall可不是firewalld)即可。
[root@Geeklp201 ~]# yum -y install firewall-config
3、如果你的发行版已经安装了安装了firewalld但是不确定是否为最新版,那么就需要进行一下更新。
[root@Geeklp201 ~]# yum -y update firewalld
4、安装完成,顺便查询一下安装详细信息
[root@Geeklp201 ~]# rpm -qi firewalld firewall-config 
Name        : firewalld
Version     : 0.4.4.4
Release     : 6.el7
Architecture: noarch
Install Date: 2017年10月18日 星期三 16时31分44秒
Group       : Unspecified
Size        : 1852322
License     : GPLv2+
Signature   : RSA/SHA256, 2017年08月10日 星期四 23时54分42秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : firewalld-0.4.4.4-6.el7.src.rpm
Build Date  : 2017年08月05日 星期六 05时14分47秒
Build Host  : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.firewalld.org
Summary     : A firewall daemon with D-Bus interface providing a dynamic firewall
Description :
firewalld is a firewall service daemon that provides a dynamic customizable
firewall with a D-Bus interface.
Name        : firewall-config
Version     : 0.4.4.4
Release     : 6.el7
Architecture: noarch
Install Date: 2017年10月25日 星期三 15时32分18秒
Group       : Unspecified
Size        : 1158110
License     : GPLv2+
Signature   : RSA/SHA256, 2017年08月10日 星期四 23时54分38秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : firewalld-0.4.4.4-6.el7.src.rpm
Build Date  : 2017年08月05日 星期六 05时14分47秒
Build Host  : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.firewalld.org
Summary     : Firewall configuration application
Description :
The firewall configuration application provides an configuration interface for
firewalld.
三、配置与使用

启动firewalld服务。

[root@Geeklp201 ~]# systemctl start firewalld
查看firewalld状态。
[root@Geeklp201 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 三 2017-10-25 15:34:33 CST; 44min ago
     Docs: man:firewalld(1)
 Main PID: 2159 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─2159 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

10月 25 15:34:33 Geeklp201 systemd[1]: Starting firewalld - dynamic firewall daemon...
10月 25 15:34:33 Geeklp201 systemd[1]: Started firewalld - dynamic firewall daemon.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'beyond-scope' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'failed-policy' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'reject-route' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
我们可以看到,firewalld已经正常运行,但是有一些警告。顺便提一下,firewalld服务的停止与禁用。

停止firewalld服务。

[root@Geeklp201 ~]# systemctl stop firewalld
[root@Geeklp201 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 三 2017-10-25 16:22:24 CST; 32s ago
     Docs: man:firewalld(1)
  Process: 2159 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 2159 (code=exited, status=0/SUCCESS)

10月 25 15:34:33 Geeklp201 systemd[1]: Starting firewalld - dynamic firewall daemon...
10月 25 15:34:33 Geeklp201 systemd[1]: Started firewalld - dynamic firewall daemon.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'beyond-scope' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'failed-policy' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'reject-route' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 16:22:23 Geeklp201 systemd[1]: Stopping firewalld - dynamic firewall daemon...
10月 25 16:22:24 Geeklp201 systemd[1]: Stopped firewalld - dynamic firewall daemon.
firewalld服务的禁用,也就是说在系统下次启动时是不会自动启动firewalld服务的。

[root@Geeklp201 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@Geeklp201 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

10月 25 15:34:33 Geeklp201 systemd[1]: Starting firewalld - dynamic firewall daemon...
10月 25 15:34:33 Geeklp201 systemd[1]: Started firewalld - dynamic firewall daemon.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'beyond-scope' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'failed-policy' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'reject-route' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 16:22:23 Geeklp201 systemd[1]: Stopping firewalld - dynamic firewall daemon...
10月 25 16:22:24 Geeklp201 systemd[1]: Stopped firewalld - dynamic firewall daemon.
恢复开机自动启动firewalld服务。
[root@Geeklp201 ~]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@Geeklp201 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

10月 25 15:34:33 Geeklp201 systemd[1]: Starting firewalld - dynamic firewall daemon...
10月 25 15:34:33 Geeklp201 systemd[1]: Started firewalld - dynamic firewall daemon.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'beyond-scope' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'failed-policy' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: ICMP type 'reject-route' is not supported by the kernel for ipv6.
10月 25 15:34:34 Geeklp201 firewalld[2159]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
10月 25 16:22:23 Geeklp201 systemd[1]: Stopping firewalld - dynamic firewall daemon...
10月 25 16:22:24 Geeklp201 systemd[1]: Stopped firewalld - dynamic firewall daemon.

很多人都会使用Linux系统man或者help获取帮助,在此就不做介绍了。

四、firewalld的使用详解

1、使用之前,几个需要理解的概念。

在正式使用firewalld之前,有几个概念我们必须了解一下。

由firewalld 提供的区域按照从不信任到信任的顺序排序。

丢弃(drop)任何流入网络的包都被丢弃,不作出任何响应。只允许流出的网络连接。

阻塞(block):任何进入的网络连接都被拒绝,并返回 IPv4 的 icmp-host-prohibited 报文或者 IPv6 的 icmp6-adm-prohibited 报文。只允许由该系统初始化的网络连接。

公开(public):用以可以公开的部分。你认为网络中其他的计算机不可信并且可能伤害你的计算机。只允许选中的连接接入。(You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.)

外部(external):用在路由器等启用伪装的外部网络。你认为网络中其他的计算机不可信并且可能伤害你的计算机。只允许选中的连接接入。

隔离区(dmz):用以允许隔离区(dmz)中的电脑有限地被外界网络访问。只接受被选中的连接。

工作(work):用在工作网络。你信任网络中的大多数计算机不会影响你的计算机。只接受被选中的连接。

家庭(home):用在家庭网络。你信任网络中的大多数计算机不会影响你的计算机。只接受被选中的连接。

内部(internal):用在内部网络。你信任网络中的大多数计算机不会影响你的计算机。只接受被选中的连接。

受信任的(trusted):允许所有网络连接。

2、常见问题FQA。

(1)我应该选用哪个区域?
例如,公共的 WIFI 连接应该主要为不受信任的,家庭的有线网络应该是相当可信任的。根据与你使用的网络最符合的区域进行选择。
如何配置或者增加区域?
你可以使用任何一种 firewalld 配置工具来配置或者增加区域,以及修改配置。工具有例如 firewall-config 这样的图形界面工具, firewall-cmd 这样的命令行工具,以及D-BUS接口。或者你也可以在配置文件目录中创建或者拷贝区域文件。 @PREFIX@/lib/firewalld/zones 被用于默认和备用配置,/etc/firewalld/zones 被用于用户创建和自定义配置文件。
(2)如何为网络连接设置或者修改区域?
区域设置以 ZONE= 选项 存储在网络连接的ifcfg文件中。如果这个选项缺失或者为空,firewalld 将使用配置的默认区域。
如果这个连接受到 NetworkManager 控制,你也可以使用 nm-connection-editor 来修改区域。
(3)由 NetworkManager 控制的网络连接
防火墙不能够通过 NetworkManager 显示的名称来配置网络连接,只能配置网络接口。因此在网络连接之前 NetworkManager 将配置文件所述连接对应的网络接口告诉 firewalld 。如果在配置文件中没有配置区域,接口将配置到 firewalld 的默认区域。如果网络连接使用了不止一个接口,所有的接口都会应用到 fiwewalld。接口名称的改变也将由 NetworkManager 控制并应用到firewalld。
如果一个接口断开了, NetworkManager 也将告诉 firewalld 从区域中删除该接口。当 firewalld 由 systemd 或者 init 脚本启动或者重启后,firewalld 将通知 NetworkManager 把网络连接增加到区域。

3、使用firewalld防火墙

  • 在不改变状态的条件下重新加载防火墙:

 firewall-cmd --reload
  

如果你使用 --complete-reload ,状态信息将会丢失。这个选项应当仅用于处理防火墙问题时,例如,状态信息和防火墙规则都正常,但是不能建立任何连接的情况。

  • 获取支持的区域列表

 firewall-cmd --get-zones
  

这条命令输出用空格分隔的列表。

  • 获取所有支持的服务

 firewall-cmd --get-services
  

这条命令输出用空格分隔的列表。

  • 获取所有支持的ICMP类型

 firewall-cmd --get-icmptypes
  

这条命令输出用空格分隔的列表。

  • 列出全部启用的区域的特性

 firewall-cmd --list-all-zones
  

输出格式是:


 <zone>
   interfaces: <interface1> ..
   services: <service1> ..
   ports: <port1> ..
   forward-ports: <forward port1> ..
   icmp-blocks: <icmp type1> ..
   
   ..
  
  • 输出区域 <zone> 全部启用的特性。如果生略区域,将显示默认区域的信息。

 firewall-cmd [--zone=<zone>] --list-all
  
  • 获取默认区域的网络设置

 firewall-cmd --get-default-zone
  
  • 设置默认区域

 firewall-cmd --set-default-zone=<zone>
  

流入默认区域中配置的接口的新访问请求将被置入新的默认区域。当前活动的连接将不受影响。

  • 获取活动的区域

 firewall-cmd --get-active-zones
  

这条命令将用以下格式输出每个区域所含接口:


 <zone1>: <interface1> <interface2> ..
 <zone2>: <interface3> ..
  
  • 根据接口获取区域

 firewall-cmd --get-zone-of-interface=<interface>
  

这条命令将输出接口所属的区域名称。

  • 将接口增加到区域

 firewall-cmd [--zone=<zone>] --add-interface=<interface>
  

如果接口不属于区域,接口将被增加到区域。如果区域被省略了,将使用默认区域。接口在重新加载后将重新应用。

  • 修改接口所属区域

 firewall-cmd [--zone=<zone>] --change-interface=<interface>
  

这个选项与 --add-interface 选项相似,但是当接口已经存在于另一个区域的时候,该接口将被添加到新的区域。

  • 从区域中删除一个接口

 firewall-cmd [--zone=<zone>] --remove-interface=<interface>
  
  • 查询区域中是否包含某接口

 firewall-cmd [--zone=<zone>] --query-interface=<interface>
  

返回接口是否存在于该区域。没有输出。

  • 列举区域中启用的服务

 firewall-cmd [ --zone=<zone> ] --list-services
  
  • 启用应急模式阻断所有网络连接,以防出现紧急状况

 firewall-cmd --panic-on
  
  • 禁用应急模式

 firewall-cmd --panic-off
  
应急模式在 0.3.0 版本中发生了变化
在 0.3.0 之前的 FirewallD版本中, panic 选项是   --enable-panic  与   --disable-panic.
  • 查询应急模式

 firewall-cmd --query-panic
  

此命令返回应急模式的状态,没有输出。可以使用以下方式获得状态输出:


 firewall-cmd --query-panic && echo "On" || echo "Off"
  

处理运行时区域

运行时模式下对区域进行的修改不是永久有效的。重新加载或者重启后修改将失效。

  • 启用区域中的一种服务

 firewall-cmd [--zone=<zone>] --add-service=<service> [--timeout=<seconds>]
  

此举启用区域中的一种服务。如果未指定区域,将使用默认区域。如果设定了超时时间,服务将只启用特定秒数。如果服务已经活跃,将不会有任何警告信息。

  • 例: 使区域中的 ipp-client 服务生效60秒:

 firewall-cmd --zone=home --add-service=ipp-client --timeout=60
  
  • 例: 启用默认区域中的http服务:

 firewall-cmd --add-service=http
  
  • 禁用区域中的某种服务

 firewall-cmd [--zone=<zone>] --remove-service=<service>
  

此举禁用区域中的某种服务。如果未指定区域,将使用默认区域。

  • 例: 禁止 home 区域中的 http 服务:

 firewall-cmd --zone=home --remove-service=http
  

区域种的服务将被禁用。如果服务没有启用,将不会有任何警告信息。

  • 查询区域中是否启用了特定服务

 firewall-cmd [--zone=<zone>] --query-service=<service>
  

如果服务启用,将返回1,否则返回0。没有输出信息。

  • 启用区域端口和协议组合

 firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
  

此举将启用端口和协议的组合。端口可以是一个单独的端口 <port> 或者是一个端口范围 <port>-<port> 。协议可以是 tcp 或 udp。

  • 禁用端口和协议组合

 firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
  
  • 查询区域中是否启用了端口和协议组合

 firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>
  

如果启用,此命令将有返回值。没有输出信息。

  • 启用区域中的 IP 伪装功能

 firewall-cmd [--zone=<zone>] --add-masquerade
  

此举启用区域的伪装功能。私有网络的地址将被隐藏并映射到一个公有IP。这是地址转换的一种形式,常用于路由。由于内核的限制,伪装功能仅可用于IPv4。

  • 禁用区域中的 IP 伪装

 firewall-cmd [--zone=<zone>] --remove-masquerade
  
  • 查询区域的伪装状态

 firewall-cmd [--zone=<zone>] --query-masquerade
  

如果启用,此命令将有返回值。没有输出信息。

  • 启用区域的 ICMP 阻塞功能

 firewall-cmd [--zone=<zone>] --add-icmp-block=<icmptype>
  

此举将启用选中的 Internet 控制报文协议 (ICMP) 报文进行阻塞。 ICMP 报文可以是请求信息或者创建的应答报文,以及错误应答。

  • 禁止区域的 ICMP 阻塞功能

 firewall-cmd [--zone=<zone>] --remove-icmp-block=<icmptype>
  
  • 查询区域的 ICMP 阻塞功能

 firewall-cmd [--zone=<zone>] --query-icmp-block=<icmptype>
  

如果启用,此命令将有返回值。没有输出信息。

  • 例: 阻塞区域的响应应答报文:

 firewall-cmd --zone=public --add-icmp-block=echo-reply
  
  • 在区域中启用端口转发或映射

 firewall-cmd [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  

端口可以映射到另一台主机的同一端口,也可以是同一主机或另一主机的不同端口。端口号可以是一个单独的端口 <port> 或者是端口范围 <port>-<port> 。协议可以为 tcp 或udp 。目标端口可以是端口号 <port> 或者是端口范围 <port>-<port> 。目标地址可以是 IPv4 地址。受内核限制,端口转发功能仅可用于IPv4。

  • 禁止区域的端口转发或者端口映射

 firewall-cmd [--zone=<zone>] --remove-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  
  • 查询区域的端口转发或者端口映射

 firewall-cmd [--zone=<zone>] --query-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  

如果启用,此命令将有返回值。没有输出信息。

  • 例: 将区域 home 的 ssh 转发到 127.0.0.2

 firewall-cmd --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2
  

处理永久区域

永久选项不直接影响运行时的状态。这些选项仅在重载或者重启服务时可用。为了使用运行时和永久设置,需要分别设置两者。 选项 --permanent 需要是永久设置的第一个参数。

  • 获取永久选项所支持的服务

 firewall-cmd --permanent --get-services
  
  • 获取永久选项所支持的ICMP类型列表

 firewall-cmd --permanent --get-icmptypes
  
  • 获取支持的永久区域

 firewall-cmd --permanent --get-zones
  
  • 启用区域中的服务

 firewall-cmd --permanent [--zone=<zone>] --add-service=<service>
  

此举将永久启用区域中的服务。如果未指定区域,将使用默认区域。

  • 禁用区域中的一种服务

 firewall-cmd --permanent [--zone=<zone>] --remove-service=<service>
  
  • 查询区域中的服务是否启用

 firewall-cmd --permanent [--zone=<zone>] --query-service=<service>
  

如果服务启用,此命令将有返回值。此命令没有输出信息。

  • 例: 永久启用 home 区域中的 ipp-client 服务

 firewall-cmd --permanent --zone=home --add-service=ipp-client
  
  • 永久启用区域中的一个端口-协议组合

 firewall-cmd --permanent [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>
  
  • 永久禁用区域中的一个端口-协议组合

 firewall-cmd --permanent [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
  
  • 查询区域中的端口-协议组合是否永久启用

 firewall-cmd --permanent [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>
  

如果服务启用,此命令将有返回值。此命令没有输出信息。

  • 例: 永久启用 home 区域中的 https (tcp 443) 端口

 firewall-cmd --permanent --zone=home --add-port=443/tcp
  
  • 永久启用区域中的伪装

 firewall-cmd --permanent [--zone=<zone>] --add-masquerade
  

此举启用区域的伪装功能。私有网络的地址将被隐藏并映射到一个公有IP。这是地址转换的一种形式,常用于路由。由于内核的限制,伪装功能仅可用于IPv4。

  • 永久禁用区域中的伪装

 firewall-cmd --permanent [--zone=<zone>] --remove-masquerade
  
  • 查询区域中的伪装的永久状态

 firewall-cmd --permanent [--zone=<zone>] --query-masquerade
  

如果服务启用,此命令将有返回值。此命令没有输出信息。

  • 永久启用区域中的ICMP阻塞

 firewall-cmd --permanent [--zone=<zone>] --add-icmp-block=<icmptype>
  

此举将启用选中的 Internet 控制报文协议 (ICMP) 报文进行阻塞。 ICMP 报文可以是请求信息或者创建的应答报文或错误应答报文。

  • 永久禁用区域中的ICMP阻塞

 firewall-cmd --permanent [--zone=<zone>] --remove-icmp-block=<icmptype>
  
  • 查询区域中的ICMP永久状态

 firewall-cmd --permanent [--zone=<zone>] --query-icmp-block=<icmptype>
  

如果服务启用,此命令将有返回值。此命令没有输出信息。

  • 例: 阻塞公共区域中的响应应答报文:

 firewall-cmd --permanent --zone=public --add-icmp-block=echo-reply
  
  • 在区域中永久启用端口转发或映射

 firewall-cmd --permanent [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  

端口可以映射到另一台主机的同一端口,也可以是同一主机或另一主机的不同端口。端口号可以是一个单独的端口 <port> 或者是端口范围 <port>-<port> 。协议可以为 tcp 或udp 。目标端口可以是端口号 <port> 或者是端口范围 <port>-<port> 。目标地址可以是 IPv4 地址。受内核限制,端口转发功能仅可用于IPv4。

  • 永久禁止区域的端口转发或者端口映射

 firewall-cmd --permanent [--zone=<zone>] --remove-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  
  • 查询区域的端口转发或者端口映射状态

 firewall-cmd --permanent [--zone=<zone>] --query-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  

如果服务启用,此命令将有返回值。此命令没有输出信息。

  • 例: 将 home 区域的 ssh 服务转发到 127.0.0.2

 firewall-cmd --permanent --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2
  

直接选项

直接选项主要用于使服务和应用程序能够增加规则。 规则不会被保存,在重新加载或者重启之后必须再次提交。传递的参数 <args> 与 iptables, ip6tables 以及 ebtables 一致。

选项 --direct 需要是直接选项的第一个参数。

  • 将命令传递给防火墙。参数 <args> 可以是 iptables, ip6tables 以及 ebtables 命令行参数。

 firewall-cmd --direct --passthrough { ipv4 | ipv6 | eb } <args>
  
  • 为表 <table> 增加一个新链 <chain> 。

 firewall-cmd --direct --add-chain { ipv4 | ipv6 | eb } <table> <chain>
  
  • 从表 <table> 中删除链 <chain> 。

 firewall-cmd --direct --remove-chain { ipv4 | ipv6 | eb } <table> <chain>
  
  • 查询 <chain> 链是否存在与表 <table>. 如果是,返回0,否则返回1.

 firewall-cmd --direct --query-chain { ipv4 | ipv6 | eb } <table> <chain>
  

如果启用,此命令将有返回值。此命令没有输出信息。

  • 获取用空格分隔的表 <table> 中链的列表。

 firewall-cmd --direct --get-chains { ipv4 | ipv6 | eb } <table>
  
  • 为表 <table> 增加一条参数为 <args> 的链 <chain> ,优先级设定为 <priority>。

 firewall-cmd --direct --add-rule { ipv4 | ipv6 | eb } <table> <chain> <priority> <args>
  
  • 从表 <table> 中删除带参数 <args> 的链 <chain>。

 firewall-cmd --direct --remove-rule { ipv4 | ipv6 | eb } <table> <chain> <args>
  
  • 查询 带参数 <args> 的链 <chain> 是否存在表 <table> 中. 如果是,返回0,否则返回1.

 firewall-cmd --direct --query-rule { ipv4 | ipv6 | eb } <table> <chain> <args>
  

如果启用,此命令将有返回值。此命令没有输出信息。

  • 获取表 <table> 中所有增加到链 <chain> 的规则,并用换行分隔。

 firewall-cmd --direct --get-rules { ipv4 | ipv6 | eb } <table> <chain>  

参考文章:

http://fedoraproject.org/wiki/FirewallD/zh-cn#.E4.BD.BF.E7.94.A8_FirewallD_.E6.9E.84.E5.BB.BA.E5.8A.A8.E6.80.81.E9.98.B2.E7.81.AB.E5.A2.99

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sec-using_firewalls#sec-Introduction_to_firewalld

转载于:https://www.cnblogs.com/aceboy/p/7820199.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CentOS7中firewalld的安装与使用详解 的相关文章

随机推荐

  • 解决Navicat无法连接到MySQL的问题

    解决Navicat无法连接到MySQL的问题 问题一 xff1a 本地IP xff08 xxx xxx xxx xxx xff09 没有访问远程数据库的权限 于是下面开启本地IP xff08 xxx xxx xxx xxx xff09 对远
  • Linux下用于查看系统当前登录用户信息的4种方法

    https www cnblogs com weijiangbao p 7868965 html 转载于 https www cnblogs com wuzm p 11377948 html
  • python学习

    https www cnblogs com dinghanhua tag python default html page 61 2 转载于 https www cnblogs com wuzm p 11381519 html
  • python学习笔记(8)迭代器和生成器

    迭代器 迭代是Python最强大的功能之一 xff0c 是访问集合元素的一种方式 迭代器是一个可以记住遍历的位置的对象 迭代器对象从集合的第一个元素开始访问 xff0c 直到所有的元素被访问完结束 迭代器只能往前不会后退 迭代器有两个基本的
  • 基于立体视觉和GPU加速的视觉里程系统(VINS)

    注意 xff1a 本文只适用于 Kerloud SLAM Indoor无人机产品 Kerloud SLAM Indoor配备有Nvidia TX2模块和Intel Realsense D435i立体摄像头 凭借更强大的GPU内核 xff0c
  • python学习笔记(9)函数(一)

    定义一个函数 你可以定义一个由自己想要功能的函数 xff0c 以下是简单的规则 xff1a 函数代码块以 def 关键词开头 xff0c 后接函数标识符名称和圆括号 任何传入参数和自变量必须放在圆括号中间 xff0c 圆括号之间可以用于定义
  • python学习笔记(10)函数(二)

    xff08 函数的参数 amp 递归函数 xff09 一 函数的参数 Python的函数定义非常简单 xff0c 但灵活度却非常大 除了正常定义的必选参数外 xff0c 还可以使用默认参数 可变参数和关键字参数 xff0c 使得函数定义出来
  • python学习笔记(2)数据类型-字符串

    字符串是 Python 中最常用的数据类型 我们可以使用引号 39 或 34 来创建字符串 创建字符串很简单 xff0c 只要为变量分配一个值即可 例如 xff1a var1 61 39 Hello World 39 var2 61 34
  • python学习笔记(11)文件操作

    一 读文件 读写文件是最常见的IO操作 Python内置了读写文件的函数 xff0c 用法和C是兼容的 读写文件前 xff0c 我们先必须了解一下 xff0c 在磁盘上读写文件的功能都是由操作系统提供的 xff0c 现代操作系统不允许普通的
  • 作业2

    作业2 xff1a 写一个随机产生138开头手机号的程序 1 输入一个数量 xff0c 产生xx条手机号 prefix 61 39 138 39 2 产生的这些手机号不能重复 转载于 https www cnblogs com wuzm p
  • mysql索引详细介绍

    博客 xff1a https blog csdn net tongdanping article details 79878302 E4 B8 89 E3 80 81 E7 B4 A2 E5 BC 95 E7 9A 84 E5 88 86
  • 作业1

    作业一 xff1a 写一个登录的程序 xff0c 1 最多登陆失败3次 2 登录成功 xff0c 提示欢迎xx登录 xff0c 今天的日期是xxx xff0c 程序结束 3 要检验输入是否为空 账号和密码不能为空 4 账号不区分大小写 im
  • 常用的SQL优化

    转自 xff1a https www cnblogs com Cheney222 articles 5876382 html 一 优化 SQL 语句的一般步骤 1 通过 show status 命令了解各种 SQL 的执行频率 MySQL
  • B+tree

    https www cnblogs com nullzx p 8729425 html 简介 xff1a 本文主要介绍了B树和B 43 树的插入 删除操作 写这篇博客的目的是发现没有相关博客以举例的方式详细介绍B 43 树的相关操作 xff
  • Mysql监控调优

    一 Mysql性能介绍 1 什么是Mysql xff1f 它有什么优点 xff1f MySQL是一个关系型数据库管理系统 xff0c 由瑞典MySQL AB公司开发 xff0c 目前属于Oracle公司 MySQL是一种关联数据库管理系统
  • [云讷科技] Kerloud PX4飞控的EKF2程序导航

    一 介绍 EKF拓展卡尔曼滤波器是px4开源飞控框架采用的核心状态估计方法 xff0c EKF2是px4飞控中的对应的软件模块 xff0c 可以支持各类传感器信号 xff0c 包括IMU xff0c 磁感计 xff0c 激光测距仪 xff0
  • 第5.4节 Python函数中的变量及作用域

    一 函数中的变量使用规则 函数执行时 xff0c 使用的全局空间是调用方的全局空间 xff0c 参数及函数使用的局部变量存储在函数单独的局部名字空间内 xff1b 函数的形参在函数中修改了值时 xff0c 并不影响调用方本身的数据 xff0
  • PX4 IO [14] serial [转载]

    PX4 IO 14 serial PX4 IO 14 serial 转载请注明出处 更多笔记请访问我的博客 xff1a merafour blog 163 com 2014
  • 《Windows核心编程》第3章——深入理解handle

    本文借助windbg来理解程序中的函数如何使用handle对句柄表进行查询的 所以先要开启Win7下Windbg的内和调试功能 解决win7下内核调试的问题 win7下debug默认无法进行内核调试 xff08 xff01 process等
  • CentOS7中firewalld的安装与使用详解

    一 软件环境 root 64 Geeklp201 cat etc redhat release CentOS Linux release 7 4 1708 Core 二 安装firewalld 1 firewalld提供了支持网络 防火墙区