[轉帖]Centos7防火牆配置rich-rule實現IP端口限制訪問

Centos7防火牆配置rich-rule實現IP端口限制訪問

版權聲明:本文爲博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
本文鏈接: https://blog.csdn.net/sunny05296/article/details/87634602

Centos7防火牆配置rich-rule實現IP端口限制訪問

最初配置3306端口允許訪問,後來根據業務需求,需要嚴格限制僅允許指定IP訪問3306端口。
可以通過防火牆配置rich-rule實現。

#Step1:刪除原有的3306端口訪問規則
firewall-cmd --permanent --remove-port=3306/tcp

#Step2:添加規則
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address=" 192.168.1.100" port protocol="tcp" port="3306" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="127.0.0.1" port protocol="tcp" port="3306" accept"

#Step3:生效規則
firewall-cmd --reload

#Step4:查看結果
firewall-cmd --list-all

#附:如果需要刪除規則,參考
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address=" 192.168.1.100" port protocol="tcp" port="3306" accept"
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="127.0.0.1" port protocol="tcp" port="3306" accept"
 

 

其他更多規則,可以使用命令查看:man firewalld.richlanguage

#添加網段

firewall-cmd --permanent --zone="public" --add-rich-rule="rule family="ipv4" source address="10.30.125.0/24" drop"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章