centos系統中firewall-cmd的一些配置


1、firewall防火牆配置:

yum install firewalld #安裝
systemctl start firewalld #啟動
systemctl enable firewalld #設置開機啟動
systemctl stop firewalld #關閉
systemctl disable firewalld #取消開機啟動


2、端口控制策略:
firewall-cmd --zone=public --add-port=6379/tcp --permanent #開放6379端口
firewall-cmd --zone=public --remove-port=6379/tcp --permanet #刪除6379端口
firewall-cmd --reload #配置立即生效
firewall-cmd --zone=public --list-ports #查看當前防火牆開放的端口
systemctl stop firewalld.service #關閉防火牆
firewall-cmd --state #查看防火牆狀態
netstat -lnpt #查看端口開放狀態

firewall-cmd --list-all #查看防火牆規則(只顯示/etc/firewalld/zones/public.xml中防火牆策略)

firewall-cmd --list-all-zones #查看所有的防火牆策略(即顯示/etc/firewalld/zones/下的所有策略)
firewall-cmd --reload #重新加載配置文件

#禁止IP(123.56.161.140)訪問本機所有服務
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="123.56.161.140" drop'
#從防火牆中刪除策略: 禁止機器IP(123.56.161.140)訪問本機所有服務
firewall-cmd --permanent --remove-rich-rule='rule family=ipv4 source address="123.56.161.140" drop'
#禁止一個B類IP段地址訪問本機,比如禁止123.56.*.*
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="123.56.0.0/16" drop'
#禁止一個C類IP段地址訪問本機,比如禁止123.56.161.*
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="123.56.161.0/24" drop'

#允許http服務(對應服務策略目錄:/usr/lib/firewalld/services/)
firewall-cmd --permanent --add-service=http
#關閉http服務(對應服務策略目錄:/usr/lib/firewalld/services/)
firewall-cmd --permanent --remove-service=http
#允許端口:3389
firewall-cmd --permanent --add-port=3389/tcp
#關閉放行中端口:3389
firewall-cmd --permanent --remove-port=3389/tcp
#允許端口:1-3389
firewall-cmd --permanent --add-port=1-3389/tcp
#更改配置后一定要重新加載配置文件:
firewall-cmd --reload


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM