理论+实操 :linux中firewalld防火墙基础————理论讲解

文章目录


前言

  • firewalld概述、firewalld 中的d代表服务
  • firewalld 和 iptables 的关系
  • firewalld 网络区域
  • firewalld 防火墙的配置方法
  • firewall-config 图形工具
  • firewalld防火墙案例

管理防火墙工具

1.图形化管理工具 firewall-config

2.命令管理工具 iptables(操作复杂) firewall-cmd

iptables

一 : 什么是iptables

iptables 只是linux防火墙管理工具而已,真正实现防火墙功能的是netfilter,我们配置了iptables规则后netfilter通过这些规则来进行防火墙过滤等操作

netfilter模块:

​ 它是主要的工作模块,位于内核中,在网络层的五个位置(也就是防火墙四表五链中的五链)注册了一些函数,用来抓取数据包;把数据包的信息拿出来匹配各个链位置在对应表中的规则:匹配之后,进行相应的处理accept、drop等等。

下面这张图很明了的说明了netfilter和iptables之间的关系
在这里插入图片描述

只要有操作系统,就有防火墙

accept 同意 drop 拒绝

网络接口层从某种意义上是二层的mac

在这里插入图片描述

二 : 四表五链

链就是执行的步骤:共有五个

进路由(prerouting)、

进系统(input)、

转发(forward)、

出系统(output)、

出路由(postrouting);

表就是存储的规则:数据包到了该链处,会去对应表中查询设置的规则,然后决定是否放行、丢弃、转发还是修改等等操作。

2.1 具体的四表

  • filter表——过滤数据包
    • 是默认的表
  • nat表——用于网络地址转换(ip、端口)
    • 地址转换时匹配这个表
  • mangle表——修改数据包的服务类型、TTL、并且可以配置路由实现QOS
    • 修改数据包时用到,很少用到
  • raw表——决定数据包是否被状态跟踪机制处理
    • 打标记时使用,用的少

表——————链————规则

一个表——一个表当中包含多个链——一个链当中包含多个规则

进路由、出路由 地址转换时用

2.2 具体的五链

硬件防火墙效果大于软件防火墙,软件防火墙只是多一道防护

  • INPUT链————进来的数据包应用此规则链中的策略
  • OUTPUT链————外出的数据包应用此规则链的策略
  • FORWARD链————转发数据包时应用此规则链中的策略
  • PREOUTING链————对数据包作路由选择前应用此链中的规则(所有的数据包进来的时候都先由这个链处理)
  • POSTROUTING链————对数据包作路由选择后应用此链中的规则(所有的数据包出来的时候都先由这个链处理)

2.3 四表五链之间的关系

五链 raw表(打标记) mangle表(修改数据包类型) nat表(地址转换) filter表(过滤数据包)
PREROUTING链(进路由) - - -
INPUT链(进系统) - -
FORWARD链(数据包转发) - -
OUTPUT链(出系统) - - - -
POSTROUTING链(出路由) - -
  • filter表——过滤数据包
    • 是默认的表
  • nat表——用于网络地址转换(ip、端口)
    • 地址转换时匹配这个表
  • mangle表——修改数据包的服务类型、TTL、并且可以配置路由实现QOS
    • 修改数据包时用到,很少用到
  • raw表——决定数据包是否被状态跟踪机制处理
    • 打标记时使用,用的少

三 : iptables语法格式

iptables [ -t 表名 ] 选项 [ 链名 ] [ 条件 ] [ -j 控制类型 ]

iptables 常用参数

-P 设置默认策略:iptables

-P INPUT (DROP | ACCEPT)

-F 清空规则链

-L 查看规则链

-A 在规则连的末尾插入新的规则

-I num 在规则连的头部加入新规则 //大写的i

-D num 删除某一条规则

-s 匹配来源地址IP/MASK,加叹号“!”表示除这个IP外

-d 匹配目标地址

-i 网卡名称 匹配从这块网卡流入的数据

-o 网卡名称 匹配从这块网卡流出的数据

-p 匹配协议,如tcp,udp,icmp

–dport num 匹配目标端口号

–sport num 匹配来源端口号

在这里插入图片描述

-I 规则链 -i网卡 -p 协议 --dport 目标端口 -s 源地址 -j 操作

iptables -F 清空默认的filters表

想要清空指定的表,需要-t指定表

一 : firewalld 概述

1.1 firewalld 简介

  • 支持网络区域所定义的网络链接以及接口安全等级的动态防火墙管理工具
  • 支持IPv4、IPv6 防火墙设置以及以太网桥
  • 支持服务或应用程序直接添加防火墙规则接口
  • 拥有两种配置模式
    • 运行时配置
    • 永久配置

通常防火墙的接口在两个或者两个以上,针对用途的不同可以将接口划分为不同的区域,针对区域去进行管理

1.2 linux 6 跟 linux 7 之间的区别

​ linux6与linux7 的网卡名称不同————linux6 的网卡名称 eth0

区别 linux6 linux7
网卡名称 eth0 ens33
防火墙 iptables firewalld,iptables

二 : firewalld 和 iptales 的关系

2.1 netfilter

  • 位于linux内核中的包过滤功能体系
  • 被称为linux防火墙的“内核态”

2.2 firewalld/iptabldes

  • centos7 默认的管理防火墙规则的工具(firewalld)
  • 称为linux防火墙的“用户态”

在防火墙中,发挥作用的是netfilter(内核态),不可以直接管理,只能间接管理,使用firewalld或者iptabvles

daemon 指的是进程

在这里插入图片描述
firewall-config 是图形化工具

firewall-cmd 是字符命令

使用工具或者操作去管理进程和服务

进程服务去控制封装的iptables命令,间接的去管理内核中的netfiler

真正能跟netfilter交互的是iptables,firewall去管理iptables

四表五链也就在iptables(command)中

工作原理体系图

2.3 firewalld 和 iptables 的区别

区别 firewalld iptables
配置文件 /usr/lib/firewalld/ /etc/firewalld etc/firewalld/etc/sysconfig/iptables
对规则的修改 不需要全部刷新策略,不丢失现行连接 需要全部刷新策略,丢失连接
防火墙类型 动态防火墙 静态防火墙

三 :firewalld 网络区域

3.1 区域介绍

区域 描述
drop(丢弃) 任何接收的网络数据包都被丢弃,没有任何回复。仅能有发送出去的网络连接
block(限制) 人和接受的网络连接都被IPv4的imcp-host-prohibited 信息和IPv6的icmp6-adm-prohibited 信息所拒绝
public(公共) 在公共区域内使用,不能详细网络内的其他计算机不会对您的计算机造成危害,只能接收经过选取的内容
external(外部) 特别是为路由器启用了伪装功能的外部网。您不能信任来自网络的其他计算机,不能相信他们不会对您的计算机造成危害,只能接收经过选择的链接
dmz(非军事区) 用于您的非军事区内的电脑,此区域内可公开访问,可以有限的进入您的内部网络,仅仅接收经过选择的链接
work(工作) 用于工作区。您可以基本详细网络内的其他电脑不会危害您的电脑。仅仅接收经过选择的链接
home(家庭) 用于家庭网络。您可以基本信任网络内的其他计算机不会危害您的计算机。仅仅接收经过选择的链接
internal(内部) 用于内部网络。您可以基本上信任网络内的其他计算机不会威胁您的计算机。仅仅接收经过选择的连接
trusted(信任) 可接受所有的网络连接
  • public 公共区域,默认所有端口放在这个区域

  • external 外部 通常会把链接外网的网卡放到这里

默认规则,高安全级别可以访问低安全级别,如果让外网访问内网,需要专门修改规则

比如内网的安全级别为100,外网的安全级别为0,则

内网可以访问外网,外网不可以访问内网

把提供对外服务的服务器放到内网,如果想要让外网可以访问内网,需要设置对应的配置,但是安全性方面存在隐患

于是就出现了dmz(非军事区),将dmz安全级别设置为50,将提供对外服务的服务器划分到dmz,这样安全性方面就得到了提高

但是这样也有以dmz为跳板,去访问内网的情况,为了更安全,背靠背堡垒主机的模式出现,即再加入一台硬件防火墙,将新的一台防火墙放到内网与当前硬件防火墙之间,起到隔绝的作用

即,第一道防火墙挡在外面,后面分两道线,一道是对外服务器,一道是内网,在内网的位置再添加第二道防火墙,以保护内网主机安全

可以在第一道防火墙启用流量监控清晰,实时分析数据,针对性去过滤可疑数据,

还可以在第一道防火墙放置一个蜜罐

常用的区域为:

public

external

dmz

internal

block 是阻塞模式

工作和家庭是自定义区域

低安全通向高安全需要设置入站规则

默认情况下,ens33绑定在公共区域(public)中

3.2 区域概述

  • 区域如同进入主机的安全门,每个区域都具有不同限制程度的规则
  • 可以使用一个或多个区域,但是任何一个活跃区域至少需要关联源地址或接口
  • 默认情况下,public区域是默认区域,包含所有接口(网卡)

在这里插入图片描述

iptables没有区域的概念

iptables是针对四表五链设置规则

在这里插入图片描述

3.3 firewalld数据处理流程

3.3.1 检查数据来源的源地址

  • 若源地址关联到特定的区域,则执行该区域所指定的规则
  • 若源地址未关联到特定的区域,则使用传入网络接口的区域并执行该区域所指定的规则
  • 若网络接口未关联到特定的区域,则使用默认区域并执行该区域所指定的规则

3.3.2 配置

  • 运行时配置 (内存)
    • 实时生效,并持续至firewalld重新启动或重新加载配置
    • 不中断现有连接
    • 不能修改服务配置
  • 永久配置
    • 不立即生效,除非firewalld重新启动或重新加载配置
    • 中断现有连接
    • 可以修改服务配置

备注:

​ 在业务比较繁忙时,不要设置永久配置,先设置运行时配置,不会中断原有业务,等到夜晚不繁忙的时候,再设置永久配置

四 : firewalld防火墙的配置方法

4.1 firewall-config 图形工具

4.2 firewall-cmd 命令行工具

4.3 /etc/firewalld/ 中的配置文件

  • firewalld会优先使用/etc/firewalld/中的配置,如果不存在配置文件,则使用/usr/lib/firewalld/ 中的配置
    • /etc/firewalld : 用户自定义配置文件,需要时可通过从/usr/libfirewalld/ 中拷贝
    • /usr/lib/firewalld/ : 默认配置文件,不建议修改,若恢复至默认配置,可直接删除/etc/firewalld/ 中的配置

五 : firewalld-config 图形工具

5.1 运行时配置/永久配置

在这里插入图片描述

5.2 重新加载防火墙

  • 更改永久配置并生效

在这里插入图片描述

5.3 关联网卡到指定区域

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

5.4 修改默认区域

在这里插入图片描述

在这里插入图片描述

5.5 连接状态

在这里插入图片描述

5.6 区域选项卡

  • “服务”子选项卡

在这里插入图片描述

被激活的区域(区域内有网卡存在)名会被黑色加粗;先指定要修改的区域,然后去修改服务等子选项,这些配置只对在该区域内的网卡生效

  • “端口”子选项卡

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

  • “协议”子选项卡

在这里插入图片描述

  • “源端口”子选项卡
    在这里插入图片描述

  • “伪装”子选项卡

在这里插入图片描述

  • “端口转发”子选项卡
    在这里插入图片描述

  • “icmp过滤器”子选项卡

在这里插入图片描述

5.7 “服务”选项卡

  • “模块”子选项卡
    在这里插入图片描述

  • “目标地址”子选项卡

在这里插入图片描述

六 : firewalld防火墙案例

6.1 实验环境

在这里插入图片描述

6.2 需求描述

  • 禁止主机ping服务器
  • 只允许192.168.2.130主机访问ssh服务
  • 允许所有主机访问apache服务

6.3实验操作步骤

[root@localhost ~]# rpm -q httpd
httpd-2.4.6-90.el7.centos.x86_64
[root@localhost ~]# firewall-config

6.3.1 ping操作

C:\Users\GSY>ping 192.168.247.142

正在 Ping 192.168.247.142 具有 32 字节的数据:
来自 192.168.247.142 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.247.142 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.247.142 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.247.142 的回复: 字节=32 时间<1ms TTL=64

192.168.247.142 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

关闭icmp的请求选项

在这里插入图片描述

C:\Users\GSY>ping 192.168.247.142

正在 Ping 192.168.247.142 具有 32 字节的数据:
来自 192.168.247.142 的回复: 无法访问目标主机。
来自 192.168.247.142 的回复: 无法访问目标主机。
来自 192.168.247.142 的回复: 无法访问目标主机。
来自 192.168.247.142 的回复: 无法访问目标主机。

192.168.247.142 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),

6.3.2 只允许指定主机访问ssh

[root@localhost ~]# ssh [email protected]
The authenticity of host '192.168.247.142 (192.168.247.142)' can't be established.
ECDSA key fingerprint is SHA256:dXWxtS2ShXQgfb7R672V7+l3i7rGqHBbIB5MTcFnAws.
ECDSA key fingerprint is MD5:59:fb:20:f0:28:96:5e:14:90:82:63:c9:ae:67:d6:e9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.247.142' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Last login: Mon Dec  9 13:42:31 2019 from 192.168.247.1
[root@localhost ~]# exit
登出
Connection to 192.168.247.142 closed.
[root@localhost ~]# ssh [email protected]
ssh: connect to host 192.168.247.142 port 22: No route to host
[root@localhost ~]# 
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.247.143  netmask 255.255.255.0  broadcast 192.168.247.255
        inet6 fe80::e2c1:c26d:afa1:a4ad  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:52:4d:89  txqueuelen 1000  (Ethernet)
        RX packets 602  bytes 49107 (47.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 227  bytes 24670 (24.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ssh [email protected]
[email protected]'s password: 
Last login: Mon Dec  9 14:05:12 2019 from 192.168.247.1
[root@localhost ~]# 

在这里插入图片描述

在这里插入图片描述

6.3.3 允许所有主机访问apache

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# netstat -natp | grep 'httpd'
tcp6       0      0 :::80                   :::*                    LISTEN      119597/httpd        
[root@localhost ~]# 

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

七 : firewalld-cmd

7.1 防火墙进程操作 (systemctl 选项 firewalld)

  • 选项: start stop restart status

7.2 防火墙管理操作

  • firewall-cmd命令
    • 支持全部防火墙特性
    • 对于状态和查询模式,命令只返回状态,没有其他输出
    • –permanent参数 : 携带该参数表示永久配置,否则表示运行时配置
    • [ --zone=] 选项: 不携带此选项表示针对默认区域操作,否则针对指定区域操作

7.3 查询firewalld状态

  • systemctl status firewalld
[root@localhost ~]# 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 一 2019-12-09 09:26:39 CST; 5h 14min ago
     Docs: man:firewalld(1)
 Main PID: 803 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─803 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
12月 09 14:10:14 localhost.localdomain firewalld[803]: WARNING: COMMAND_FAILED: '/usr/sb....
Hint: Some lines were ellipsized, use -l to show in full.

  • firewall-cmd --state
[root@localhost ~]# firewall-cmd --state
running
[root@localhost ~]# 

7.4 firewalld常用命令

7.5 重新加载firewalld的配置

  • firewall-cmd --reload
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# 
  • firewall-cmd --complete-reload
    • 状态信息将会丢失,多用于处理防火墙出现问题时
[root@localhost ~]# firewall-cmd --complete-reload
success
[root@localhost ~]# 
  • systemctl restart firewalld
[root@localhost ~]# systemctl restart firewalld

八 : 查询预定义信息命令

8.1 获取预定义信息

  • firewall-cmd --get-zones 查看预定义的区域
[root@localhost ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
[root@localhost ~]# 
  • firewall-cmd --get-services 查看预定义的服务
[root@localhost ~]# firewall-cmd --get-services
RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master high-availability http https imap imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kibana klogin kpasswd kshell ldap ldaps libvirt libvirt-tls managesieve mdns mosh mountd ms-wbt mssql mysql nfs nrpe ntp openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server
[root@localhost ~]# 
  • firewall-cmd --get-icmptypes 查看预定义的ICMP类型
[root@localhost ~]# firewall-cmd --get-icmptypes
address-unreachable bad-header communication-prohibited destination-unreachable echo-reply echo-request fragmentation-needed host-precedence-violation host-prohibited host-redirect host-unknown host-unreachable ip-header-bad neighbour-advertisement neighbour-solicitation network-prohibited network-redirect network-unknown network-unreachable no-route packet-too-big parameter-problem port-unreachable precedence-cutoff protocol-unreachable redirect required-option-missing router-advertisement router-solicitation source-quench source-route-failed time-exceeded timestamp-reply timestamp-request tos-host-redirect tos-host-unreachable tos-network-redirect tos-network-unreachable ttl-zero-during-reassembly ttl-zero-during-transit unknown-header-type unknown-option
[root@localhost ~]# 

8.2 显示网络连接或接口的默认区域

[root@localhost ~]# firewall-cmd --get-default-zone
public
[root@localhost ~]# 

8.3 设置网络连接或接口的默认区域为internal

[root@localhost ~]# firewall-cmd --set-default-zone=internal
success
[root@localhost ~]# 

8.4 显示已激活的所有区域

[root@localhost ~]# firewall-cmd --get-active-zones
public
  interfaces: ens33
[root@localhost ~]# 
  • 激活的条件 : 区域至少关联一个接口或一个源地址/网段

  • get 下载、显示的含义

8.5 显示ens33接口绑定的区域

[root@localhost ~]# firewall-cmd --get-zone-of-interface=ens33
public
[root@localhost ~]# 

8.6 为ens33接口绑定work区域

[root@localhost ~]# firewall-cmd --zone=work --add-interface=ens33
The interface is under control of NetworkManager, setting zone to 'work'.
success
[root@localhost ~]# 

8.7 为work区域更改绑定的网络接口ens33

[root@localhost ~]# firewall-cmd --zone=work --change-interface=ens33
The interface is under control of NetworkManager and already bound to 'work'
The interface is under control of NetworkManager, setting zone to 'work'.
success
[root@localhost ~]# 

8.8 为work区域删除绑定的网络接口ens33

[root@localhost ~]# firewall-cmd --zone=work --remove-interface=ens33
The interface is under control of NetworkManager, setting zone to default.
success
[root@localhost ~]# 

8.9 查询work区域是否包含接口ens33

[root@localhost ~]# firewall-cmd --zone=work --query-interface=ens33
no
[root@localhost ~]# 

8.10 显示区域及其规则

  • 显示所有区域及其规则
[root@localhost ~]# firewall-cmd --list-all-zones
block
  target: %%REJECT%%
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

dmz
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

drop
  target: DROP
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

external
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh
  ports: 
  protocols: 
  masquerade: yes
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

home
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh mdns samba-client dhcpv6-client
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

internal (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: ssh mdns samba-client dhcpv6-client
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

public
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh dhcpv6-client http
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

trusted
  target: ACCEPT
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

work
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh dhcpv6-client
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        

[root@localhost ~]# 

  • 显示internal区域的所有规则
[root@localhost ~]# firewall-cmd --zone=internal --list-all
internal (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: ssh mdns samba-client dhcpv6-client
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        
[root@localhost ~]# 
  • 显示默认区域的所有规则
[root@localhost ~]# firewall-cmd --list-all
internal (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: ssh mdns samba-client dhcpv6-client
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        
[root@localhost ~]# 

firewall-cmd 区域小结

在这里插入图片描述

九 :firewalld服务操作命令

9.1 显示internal 区域内允许访问的所有服务

[root@localhost ~]# firewall-cmd --zone=internal --list-services
ssh mdns samba-client dhcpv6-client

9.2 为public区域设置允许访问SMTP服务

[root@localhost ~]# firewall-cmd --zone=public --add-service=smtp
success
[root@localhost ~]# 

9.3 删除internal 区域中的SSH服务

[root@localhost ~]# firewall-cmd --zone=internal --remove-service=ssh
success
[root@localhost ~]# 

9.4 查询internal 区域中是否启用了SSH服务

[root@localhost ~]# firewall-cmd --zone=internal --query-service=ssh
no
[root@localhost ~]# 

firewall-cmd 服务配置小结

在这里插入图片描述

十 : firewalld 端口操作命令

10.1 显示internal 区域内允许访问的所有端口号

[root@localhost ~]# firewall-cmd --zone=internal --list-ports

10.2 启用internal区域22端口的TCP协议组合

[root@localhost ~]# firewall-cmd --zone=internal --add-port=22/tcp --timeout=5m
success
[root@localhost ~]# 
  • –timeout=5m : 表示5分钟后删除该端口,多用于测试目的

10.3 禁用internal 区域22端口的TCP协议组合

[root@localhost ~]# firewall-cmd --zone=internal --remove-port=22/tcp
success
[root@localhost ~]# 

10.4 查询internal 区域中是否启用了22端口和TCP协议组合

[root@localhost ~]# firewall-cmd --zone=internal --query-port=22/tcp
no
[root@localhost ~]# 

firewall-cmd 端口配置小结

在这里插入图片描述

十一 : firewalld 阻塞ICMP操作命令

11.1 显示work区域内阻塞的所有ICMP类型

[root@localhost ~]# firewall-cmd --zone=work --list-icmp-blocks

[root@localhost ~]# 

11.2 为work区域设置阻塞echo-reply类型的ICMP

[root@localhost ~]# firewall-cmd --zone=work --add-icmp-block=echo-request
success
[root@localhost ~]# 
[root@localhost ~]# firewall-cmd --zone=work --list-icmp-blocks
echo-request
[root@localhost ~]# firewall-cmd --zone=work --add-icmp-block=echo-reply 
success
[root@localhost ~]# 

11.3 删除work区域已阻塞recho-reply类型的ICMP

[root@localhost ~]# firewall-cmd --zone=work --remove-icmp-block=echo-reply 
success
[root@localhost ~]# firewall-cmd --zone=work --list-icmp-blocks
echo-request
[root@localhost ~]# 

11.4 查询work区域的echo-request类型的ICMP是否阻塞

[root@localhost ~]# firewall-cmd --zone=work --query-icmp-block=echo-request
yes
[root@localhost ~]# 

备注: 阻塞,即不让通行的意思

firewall-cmd icmp阻塞配置小结

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

rewall-cmd --zone=work --list-icmp-blocks
echo-request
[root@localhost ~]# firewall-cmd --zone=work --add-icmp-block=echo-reply
success
[root@localhost ~]#


## 11.3 删除work区域已阻塞recho-reply类型的ICMP

[root@localhost ~]# firewall-cmd --zone=work --remove-icmp-block=echo-reply
success
[root@localhost ~]# firewall-cmd --zone=work --list-icmp-blocks
echo-request
[root@localhost ~]#


## 11.4 查询work区域的echo-request类型的ICMP是否阻塞

[root@localhost ~]# firewall-cmd --zone=work --query-icmp-block=echo-request
yes
[root@localhost ~]#


备注: 阻塞,即不让通行的意思

## firewall-cmd icmp阻塞配置小结

[外链图片转存中...(img-eXFExeh8-1575881463973)]



[外链图片转存中...(img-75NI2R45-1575881463973)]

[外链图片转存中...(img-7B8lv5dN-1575881463973)]

[外链图片转存中...(img-6ZHWYoQy-1575881463974)]

[外链图片转存中...(img-glXdHi3j-1575881463974)]

[外链图片转存中...(img-QH3XiVUC-1575881463974)]

[外链图片转存中...(img-q7rkEprJ-1575881463975)]

[外链图片转存中...(img-u8vEkWwn-1575881463975)]

[外链图片转存中...(img-oECAp31C-1575881463975)]

















发布了87 篇原创文章 · 获赞 26 · 访问量 4552

猜你喜欢

转载自blog.csdn.net/Lfwthotpt/article/details/103460769