centos: firewalld 1

學習apache安裝的時候須要打開80端口,因爲centos 7版本之後默認使用firewalld後,網上關於iptables的設置方法已經無論用了,想着反正iptable也不會用,索性直接搬官方文檔,學習firewalld了,好像比iptables要簡單點了。html

官方文檔地址:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html#sec-Introduction_to_firewalldapache

一、firewalld簡介 firewalld是centos7的一大特性,最大的好處有兩個:支持動態更新,不用重啓服務;第二個就是加入了防火牆的「zone」概念centos

firewalld有圖形界面和工具界面,因爲我在服務器上使用,圖形界面請參照官方文檔,本文以字符界面作介紹服務器

firewalld的字符界面管理工具是 firewall-cmdtcp

firewalld默認配置文件有兩個:/usr/lib/firewalld/ (系統配置,儘可能不要修改)和 /etc/firewalld/ (用戶配置地址)ide

zone概念: 硬件防火牆默認通常有三個區,firewalld引入這一律念系統默認存在如下區域(根據文檔本身理解,若是有誤請指正): drop:默認丟棄全部包 block:拒絕全部外部鏈接,容許內部發起的鏈接 public:指定外部鏈接能夠進入 external:這個不太明白,功能上和上面相同,容許指定的外部鏈接 dmz:和硬件防火牆同樣,受限制的公共鏈接能夠進入 work:工做區,概念和workgoup同樣,也是指定的外部鏈接容許 home:相似家庭組 internal:信任全部鏈接 對防火牆不算太熟悉,還沒想明白public、external、dmz、work、home從功能上都須要自定義容許鏈接,具體使用上的區別還需高人指點工具

二、安裝firewalld root執行 # yum install firewalld firewall-config學習

三、運行、中止、禁用firewalld 啓動:# systemctl start firewalld 查看狀態:# systemctl status firewalld 或者 firewall-cmd --state 中止:# systemctl disable firewalld 禁用:# systemctl stop firewalldui

四、配置firewalld 查看版本:$ firewall-cmd --version 查看幫助:$ firewall-cmd --help 查看設置: 顯示狀態:$ firewall-cmd --state 查看區域信息: $ firewall-cmd --get-active-zones 查看指定接口所屬區域:$ firewall-cmd --get-zone-of-interface=eth0 拒絕全部包:# firewall-cmd --panic-on 取消拒絕狀態:# firewall-cmd --panic-off 查看是否拒絕:$ firewall-cmd --query-paniccentos7

更新防火牆規則:# firewall-cmd --reload # firewall-cmd --complete-reload 二者的區別就是第一個無需斷開鏈接,就是firewalld特性之一動態添加規則,第二個須要斷開鏈接,相似重啓服務

將接口添加到區域,默認接口都在public

firewall-cmd --zone=public --add-interface=eth0

永久生效再加上 --permanent 而後reload防火牆

設置默認接口區域

firewall-cmd --set-default-zone=public

當即生效無需重啓

打開端口(貌似這個才最經常使用) 查看全部打開的端口:

firewall-cmd --zone=dmz --list-ports

加入一個端口到區域:

firewall-cmd --zone=dmz --add-port=8080/tcp

若要永久生效方法同上

打開一個服務,相似於將端口可視化,服務須要在配置文件中添加,/etc/firewalld 目錄下有services文件夾,這個不詳細說了,詳情參考文檔

firewall-cmd --zone=work --add-service=smtp

移除服務

firewall-cmd --zone=work --remove-service=smtp

還有端口轉發功能、自定義複雜規則功能、lockdown,因爲還沒用到,之後再學習

相關文章
相關標籤/搜索