CentOS7最小化安裝後要做的事(3):防火牆基礎配置

weixin_34208283發表於2018-02-25

考慮到《可能是目前最詳細簡明的CentOS7安裝與管理教程》一文太長,以及簡書目前不支援導航目錄,閱讀起來過於不便,故對其分解成《CentOS7最小化安裝後要做的事》系列,方便以後有針對性的豐富內容。

firewalld

在centos7時代防火牆已由iptable轉向firewalld,既然本文講的是centos7,那麼我們就直接接受並適應它。?

在此之前,要提一提systemctl

systemd 是一個 Linux 系統基礎元件的集合,提供了一個系統和服務管理器,執行為 PID 1 並負責啟動其它程式。功能包括:支援並行化任務;同時採用 socket 式與 D-Bus 匯流排式啟用服務;按需啟動守護程式(daemon);利用 Linux 的 cgroups 監視程式;支援快照和系統恢復;維護掛載點和自動掛載點;各服務間基於依賴關係進行精密控制。systemd 支援 SysV 和 LSB 初始指令碼,可以替代 sysvinit。除此之外,功能還包括日誌程式、控制基礎系統配置,維護登陸使用者列表以及系統賬戶、執行時目錄和設定,可以執行容器和虛擬機器,可以簡單的管理網路配置、網路時間同步、日誌轉發和名稱解析等。

簡單說就是:systemctl是CentOS7的服務管理工具中主要的工具,它融合之前service和chkconfig的功能於一體。在系統服務管理中推薦使用systemctl來管理。

下面以firewalld服務為例:

  1. firewalld服務啟用/停用

啟動一個服務: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
檢視已啟動的服務列表:systemctl list-unit-files|grep enabled
檢視啟動失敗的服務列表:systemctl --failed

2.配置firewalld-cmd

檢視版本: firewall-cmd –version
檢視幫助: firewall-cmd –help
顯示狀態: firewall-cmd –state
檢視所有開啟的埠: firewall-cmd –zone=public –list-ports
更新防火牆規則: firewall-cmd –reload
檢視區域資訊: firewall-cmd –get-active-zones
檢視指定介面所屬區域: firewall-cmd –get-zone-of-interface=eth0
拒絕所有包:firewall-cmd –panic-on
取消拒絕狀態: firewall-cmd –panic-off
檢視是否拒絕: firewall-cmd –query-panic

3.埠管理:

新增: firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent 永久生效,沒有此引數重啟後失效)
重新載入:firewall-cmd --reload
檢視:firewall-cmd --zone= public --query-port=80/tcp
刪除:firewall-cmd --zone= public --remove-port=80/tcp --permanent

正式環境下,看需要選擇是否使用防火牆,這裡為了方便後續配置,就先將其關閉:

關閉防火牆 systemctl stop firewalld
禁止開機自啟systemctl disable firewalld
檢視防火牆狀態systemctl status firewalld

1328486-923f4812fed83f54.png
防火牆狀態

相關文章