centos7 firewall指定IP與端口訪問(常用)


基本使用

啟動:systemctl start firewalld

關閉:systemctl stop firewalld

查看狀態:systemctl status firewalld

開機禁用:systemctl disable firewalld

開機啟用:systemctl enable firewalld

配置firewalld-cmd

查看版本:firewall-cmd --version

查看幫助:firewall-cmd --help

顯示狀態:firewall-cmd --state

查看所有打開的端口:firewall-cmd --zone=public --list-ports

更新防火牆規則:firewall-cmd --reload

端口開放

添加:firewall-cmd --zone=public --add-port=80/tcp --permanent

重新載入:firewall-cmd --reload

刪除:firewall-cmd --zone= public --remove-port=80/tcp --permanent

端口轉發

添加(例如3306 -> 3336):

firewall-cmd --permanent --zone=public --add-forward-port=port=3336:proto=tcp:toport=3306:toaddr=

刪除:

firewall-cmd --permanent --remove-forward-port=port=3306:proto=tcp:toport=3336:toaddr=

查看轉發的端口:firewall-cmd --list-forward-ports

查看當前開了哪些端口

其實一個服務對應一個端口,每個服務對應/usr/lib/firewalld/services下面一個xml文件。

firewall-cmd --list-services

查看還有哪些服務可以打開

firewall-cmd --get-services

查看所有打開的端口: 

firewall-cmd --zone=public --list-ports

更新防火牆規則: 

firewall-cmd --reload

 

# 添加多個端口
firewall-cmd --permanent --zone=public --add-port=8080-8083/tcp

# 刪除某個端口
firewall-cmd --permanent --zone=public --remove-port=81/tcp

# 針對某個 IP開放端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="6379" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.233" accept"

# 刪除某個IP
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.51" accept"

# 針對一個ip段訪問
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="9200" accept"

# 添加操作后別忘了執行重載
firewall-cmd --reload

  

 


免責聲明!

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



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