前言
- 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=<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 open*** 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 ~]#
備註: 阻塞,即不讓通行的意思