1. 程式人生 > >Linux系統管理初步(五)Linux系統的防火墻-firewalld 編輯中

Linux系統管理初步(五)Linux系統的防火墻-firewalld 編輯中

from lin proc isa network set http sele 被拒

CentOS7中,系統自帶的netfilter操作程序由iptables變為firewalld。

一、firewalld中的9個zone

firewalld中有9個zone,各個zone的說明如下
drop
Any incoming network packets are dropped; there is no reply. Only outgoing network connections are possible.
block
Any incoming network connections are rejected with an icmp-host-prohibited message for IPv4 and icmp6-adm-prohibited for IPv6. Only network connections initiated from within the system are possible.

public
For use in public areas. You do not trust the other computers on the network to not harm your computer. Only selected incoming connections are accepted.
external
For use on external networks with masquerading enabled, especially for routers. You do not trust the other computers on the network to not harm your computer. Only selected incoming connections are accepted.
dmz
For computers in your demilitarized zone that are publicly-accessible with limited access to your internal network. Only selected incoming connections are accepted.
work
For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.
home
For use in home areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.
internal
For use on internal networks. You mostly trust the other computers on the networks to not harm your computer. Only selected incoming connections are accepted.
trusted
All network connections are accepted.

譯文:
由firewalld 提供的區域按照從不信任到信任的順序排序。
丟棄 drop
任何流入網絡的包都被丟棄,不作出任何響應。只允許流出的網絡連接。
阻塞 block
任何進入的網絡連接都被拒絕,並返回 IPv4 的 icmp-host-prohibited 報文或者 IPv6 的 icmp6-adm-prohibited 報文。只允許由該系統初始化的網絡連接。
公開 public
用以可以公開的部分。你認為網絡中其他的計算機不可信並且可能傷害你的計算機。只允許選中的連接接入。
外部 external
用在路由器等啟用偽裝的外部網絡。你認為網絡中其他的計算機不可信並且可能傷害你的計算機。只允許選中的連接接入。
隔離區dmz
用以允許隔離區(dmz)中的電腦有限地被外界網絡訪問。只接受被選中的連接。
工作 work
用在工作網絡。你信任網絡中的大多數計算機不會影響你的計算機。只接受被選中的連接。
家庭 home
用在家庭網絡。你信任網絡中的大多數計算機不會影響你的計算機。只接受被選中的連接。
內部 internal
用在內部網絡。你信任網絡中的大多數計算機不會影響你的計算機。只接受被選中的連接。
受信任的 trusted
允許所有網絡連接。

二、firewalld的應用

操作前,我們看下當前系統中應用的是哪種防火墻程序。

systemctl list-units --all --type=service |egrep ‘firewalld|ip6tables|iptables‘

技術分享圖片

看active那一列,active的就是在用的程序,如果你看到firewalld那一行是inactive的,那我們就用下列命令把他啟動

systemctl start firewalld #
systemctl enable firewalld #

如果iptables.service是active的那我們也要把他停用

systemctl stop iptables
systemctl disable iptables

都執行完後可以再重復第一條命令看下服務狀態是否跟截圖一致。

firewall命令有點像一個英語句子,好理解,但是輸入有點煩
比如說

firewall-cmd --get-default-zone
firewall-cmd --set-default-zone=work
firewall-cmd --get-zone-interface=ens33

命令行操作

(一)操作網卡與zone的關系

1、查看新加接口默認的zone

firewall-cmd --get-default-zone

技術分享圖片

2、設定新接口加入時的默認zone

firewall-cmd --set-default-zone=work

技術分享圖片
3、查看接口所在的zone

firewall-cmd --get-zone-of-interface=ens33

技術分享圖片

4、給指定的網卡設置zone

firewall-cmd --zone=dmz --d-interface=ens33

技術分享圖片

5、更改某個網卡的zone

firewall-cmd --zone=public --change-interface=ens33

技術分享圖片

6、查看系統所有網卡所在的zone

firewall-cmd --get-active-zones

技術分享圖片

(二)操作zone的service

Linux系統管理初步(五)Linux系統的防火墻-firewalld 編輯中