|
初始化后开启防火墙流程
linux centos7 默认防火墙是关闭的,设置了开启端口后一定要重启防火墙,否则端口开启会不起作用
查看已开启的端口
firewall-cmd --list-ports
查看防火墙状态
firewall-cmd --state
开启防火墙
systemctl start firewalld
开启80端口(永久)(默认public区域)
firewall-cmd --zone=public --add-port=80/tcp --permanent
配置富规则限制某ip网段无法访问某端口
firewall-cmd --add-rich-rule='rule family="ipv4" source address="102.200.0.0/16" port port="443" protocol="tcp" drop' --permanent
firewall-cmd --add-rich-rule='rule family="ipv4" source address="102.200.0.0/16" port port="80" protocol="tcp" drop' --permanent
firewall-cmd --add-rich-rule='rule family="ipv4" source address="105.104.0.0/16" port port="80" protocol="tcp" drop' --permanent
firewall-cmd --add-rich-rule='rule family="ipv4" source address="109.104.0.0/16" port port="443" protocol="tcp" drop' --permanent
网段填写详情: https://www.swztdza.cn/dalt/forum.php?mod=viewthread&tid=227
重启防火墙生效
firewall-cmd --reload
查看已开启的端口
firewall-cmd --list-ports
查看已生效的富规则
firewall-cmd --list-rich-rules
|