firewalld必须用systemctl管理:启动用systemctl start firewalld,启用开机自启需systemctl enable firewalld;关闭分临时(systemctl stop)和永久(stop+disable);状态须同时用systemctl status firewalld和firewall-cmd --state双重验证。

在CentOS 7中,firewalld是默认的防火墙服务,必须通过systemctl管理其运行状态,直接kill进程或用iptables命令无法真正关闭它。
开启firewalld防火墙
执行启动命令即可让firewalld立即运行:
systemctl start firewalld
这一步不会报错,但如果你之前禁用了开机自启,重启后防火墙会再次停止。所以建议紧接着设置开机启用:
systemctl enable firewalld
【firewalld启用后不会自动放行任何端口,HTTP/SSH等服务仍需手动开放对应端口】
关闭firewalld防火墙
方法一:临时关闭(当前会话生效,重启后恢复)
systemctl stop firewalld
CentOS Linux 7.9.2009是传统CentOS Linux 7的最后主要版本,也是很多企业历史服务器中仍可能遇到的系统版本。它以稳定、兼容RHEL 7生态、文档丰富和软件支持广泛著称,曾长期用于Web服务、数据库、虚拟化节点和企业内部业务系统。不过CentOS Linux 7已于2024年6月30日停止维护,现在继续使用会面临安全补丁缺失风险。该版本更适合旧业务迁移、历史环境恢复或离
方法二:永久关闭(同时禁用开机自启)
systemctl stop firewalld → systemctl disable firewalld
注意:disable操作会移除/etc/systemd/system/multi-user.target.wants/firewalld.service软链接,下次系统启动时不再加载该服务。
验证防火墙当前状态
第一步:检查firewalld服务是否正在运行
systemctl status firewalld
第二步:确认底层防火墙引擎是否活跃(更权威)
firewall-cmd --state
如果返回running,说明firewalld已激活;返回not running则已关闭。两者结果必须一致才代表状态真实可靠——曾有用户因只查systemctl而误判,实际firewall-cmd --state返回not running,原因是服务虽启动但内部模块未就绪。

















