查看防火墙是否开启
systemctl start friewall.service
//开启防火墙
firewall-cmd --state
//查询防火墙运行状态
firewall-cmd --list-all
添加防火墙规则
放行单个端口
firewall-cmd --permanent --add-port=80/tcp
//开放80端口,允许外面访问
放行某一段端口号
firewall-cmd --permanent --zone=public --add-port=1000-2000/tcp
firewall-cmd --reload
放行某个ip进行访问
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.169 accept'
firewall-cmd --reload
放行某段IP进行访问
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.0/24 accept'
禁止某个ip进行访问
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.42 drop'
firewall-cmd --reload
放行某个ip访问某个端口
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.169 port protocol=tcp port=6379 accept'
firewall-cmd --reload
移除防火墙规则
移除一条规则
firewall-cmd --permanent --remove-port=80/tcp
firewall-cmd --reload
移除以上规则
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.1.169" port port="6379" protocol="tcp" accept'
firewall-cmd --reload
systemctl start friewall.service
//开启防火墙
firewall-cmd --state
//查询防火墙运行状态
firewall-cmd --list-all
添加防火墙规则
放行单个端口
firewall-cmd --permanent --add-port=80/tcp
//开放80端口,允许外面访问
放行某一段端口号
firewall-cmd --permanent --zone=public --add-port=1000-2000/tcp
firewall-cmd --reload
放行某个ip进行访问
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.169 accept'
firewall-cmd --reload
放行某段IP进行访问
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.0/24 accept'
禁止某个ip进行访问
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.42 drop'
firewall-cmd --reload
放行某个ip访问某个端口
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.169 port protocol=tcp port=6379 accept'
firewall-cmd --reload
移除防火墙规则
移除一条规则
firewall-cmd --permanent --remove-port=80/tcp
firewall-cmd --reload
移除以上规则
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.1.169" port port="6379" protocol="tcp" accept'
firewall-cmd --reload