Centos7防火牆配置rich-rule實現IP端口限制訪問
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"