Centos7/RHEL7-firewalld設置訪問規則
前言
CentOS7/RHEL7系統默認的iptables管理工具是firewalld,不再是以往的iptables-services,命令用起來也是不一樣了,當然你也可以選擇卸載firewalld,安裝iptables-services。
firewalld 服務管理
1、安裝firewalld
yum -y install firewalld
2、開機啟動/禁用服務
systemctl enable/disable firewalld
3、啟動/關閉服務
systemctl start/stop firewalld
4、查看服務狀態
systemctl status firewalld
使用firewall-cmd命令設置規則
1、查看狀態
firewall-cmd --state
2、獲取活動的區域
firewall-cmd --get-active-zones
3、 獲取所有支持的服務
firewall-cmd --get-service
4、應急模式(阻斷所有的網路連接)
firewall-cmd --panic-on #開啟應急模式
firewall-cmd --panic-off #關閉應急模式
firewall-cmd --query-panic #查詢應急模式
5、修改配置文件後 使用命令重新載入
firewall-cmd --reload
6、啟用某個服務/埠
firewall-cmd --zone=public --add-service=https #臨時
firewall-cmd --permanent --zone=public --add-service=https #永久
firewall-cmd --permanent --zone=public --add-port=8080-8081/tcp #永久
firewall-cmd --zone=public --add-port=8080-8081/tcp #臨時
如果是要刪除,直接修改成remove-service或者remove-port
7、查看開啟的埠和服務
firewall-cmd --permanent --zone=public --list-services #服務空格隔開 例如 dhcpv6-client https ss
firewall-cmd --permanent --zone=public --list-ports #埠空格隔開 例如 8080-8081
在每次修改 埠和服務後 /etc/firewalld/zones/public.xml 文件就會被修改。
8、設置某個ip 訪問某個服務
firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.122.0/24" service name="http" accept" #ip 192.168.122.0/24 訪問 http
總結
防火牆預定義的服務配置文件是xml文件,目錄在 /usr/lib/firewalld/services/; 在 /etc/firewalld/services/ 這個目錄中也有配置文件,但是/etc/firewalld/services/目錄優先於 /usr/lib/firewalld/services/ 目錄。


※linux-shell命令處理json數據
※linux-磁碟掛載優化
TAG:linux運維菜 |