CentOS 7 firewalld使用简介
2019獨角獸企業重金招聘Python工程師標準>>>
Centos升級到7之后,發現無法使用iptables控制Linuxs的端口,google之后發現Centos 7使用firewalld代替了原來的iptables。下面記錄如何使用firewalld開放Linux端口:
1.快速使用說明
開啟端口
#在tcp協議上開放80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent #重新加載防火墻規則 firewall-cmd --reload開端端口區間
#在tcp協議上開放8080-8090的端口 firewall-cmd --permanent --zone=public --add-port=8080-8090/tcp #在udp協議上開放8080-8090的端口 firewall-cmd --permanent --zone=public --add-port=8080-8090/udp #重新加載防火墻規則 firewall-cmd --reload命令含義
--zone #作用域 --add-port=80/tcp #添加端口,格式為:端口/通訊協議 --permanent #永久生效,沒有此參數重啟后失效重啟防火墻
firewall-cmd --reload查詢firewalld的狀態
systemctl status firewalld2.firewalld簡介
firewalld是centos7的一大特性,最大的好處有兩個:支持動態更新,不用重啟服務;第二個就是加入了防火墻的“zone”概念
firewalld有圖形界面和工具界面,由于我在服務器上使用,圖形界面請參照官方文檔,本文以字符界面做介紹
firewalld的字符界面管理工具是?firewall-cmd?
firewalld默認配置文件有兩個:/usr/lib/firewalld/ (系統配置,盡量不要修改)和 /etc/firewalld/ (用戶配置地址)
zone概念
硬件防火墻默認一般有三個區,firewalld引入這一概念系統默認存在以下區域(根據文檔自己理解,如果有誤請指正):
對防火墻不算太熟悉,還沒想明白public、external、dmz、work、home從功能上都需要自定義允許連接,具體使用上的區別還需高人指點
3.安裝firewalld
yum install firewalld firewall-config4.firewalld常用命令
#啟動: systemctl start ?firewalld #查看狀態: systemctl status firewalld?或者?firewall-cmd --state #停止: systemctl disable firewalld #禁用: systemctl stop firewalld5.systemctl
systemctl是CentOS7的服務管理工具中主要的工具,它融合之前service和chkconfig的功能于一體。
啟動一個服務: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
6.配置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-panic #更新防火墻規則: 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=public --list-ports加入一個端口到區域:
firewall-cmd --zone=public --add-port=8080/tcp若要永久生效方法同上
打開一個服務
類似于將端口可視化,服務需要在配置文件中添加,/etc/firewalld 目錄下有services文件夾,這個不詳細說了,詳情參考文檔
firewall-cmd --zone=work --add-service=smtp移除服務
firewall-cmd --zone=work --remove-service=smtp?
轉載于:https://my.oschina.net/liuyuantao/blog/913721
總結
以上是生活随笔為你收集整理的CentOS 7 firewalld使用简介的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 9 将采用新的版本字符串格式
- 下一篇: 做梦梦到龙了是什么征兆