CentOS7 Firewall防火墙常用命令

本文详细介绍如何在CentOS系统中管理和配置防火墙,包括开启、关闭防火墙,设置端口转发,创建黑名单等操作。此外,还介绍了如何禁止被PING及重载防火墙配置的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开启防火墙
systemctl start firewalld.service
关闭防火墙
systemctl stop firewalld.service
查看防火墙状态
systemctl status firewalld.service
开启开机启动防火墙
systemctl enable firewalld.service
关闭开机启动防火墙
systemctl disable firewalld.service
开启某个端口(80)
firewall-cmd --zone=public --add-port=80/tcp --permanent   //永久
firewall-cmd --zone=public --add-port=80/tcp               //临时
端口转发
firewall-cmd --zone=public --add-masquerade --permanent    //打开IP地址伪装
//将8080转发到80
firewall-cmd --zone=public --add-forward-port=port=80:proto=tcp:toport=8080 --permanent
创建黑名单
//创建blacklist ipset
firewall-cmd --permanent --zone=public --new-ipset=blacklist --type=hash:ip
//封禁 blacklist
firewall-cmd --permanent --zone=public --add-rich-rule='rule source ipset=blacklist drop'
//查看 blacklist
firewall-cmd --ipset=blacklist --get-entries
//添加IP到黑名单
firewall-cmd --permanent --zone=public --ipset=blacklist --add-entry=212.237.51.36
firewall-cmd --permanent --zone=public --ipset=blacklist --add-entry=188.226.191.66
firewall-cmd --permanent --zone=public --ipset=blacklist --add-entry=80.211.137.182
firewall-cmd --permanent --zone=public --ipset=blacklist --add-entry=60.191.66.226
禁止被PING(丢弃ICMP包)
firewall-cmd --permanent --zone=public --add-rich-rule='rule protocol value=icmp drop'  
查看所有规则
firewall-cmd --zone=public --list-all
重载防火墙配置
firewall-cmd --reload

参考文章

云服务器 ECS CentOS 7配置默认防火墙 Firewall
https://help.aliyun.com/knowledge_detail/41317.html
RHEL7、CentOS7 下使用 Firewall 封IP
https://www.itlnmp.com/401.html
firewalld禁止被PING(丢弃ICMP包)
http://blog.youkuaiyun.com/Sidyhe/article/details/54836165?locationNum=10&fps=1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值