温馨提示×

centos防火墙如何停用

小樊
49
2026-09-27 00:49:46
栏目: 智能运维

在 CentOS 中,防火墙通常是 firewalld(CentOS 7 及以后)。下面按常见场景说明如何停用防火墙。


一、CentOS 7 / 8 / Stream(使用 firewalld)

1. 临时停止防火墙(重启后失效)

systemctl stop firewalld

2. 禁止开机启动(永久停用)

systemctl disable firewalld

3. 查看防火墙状态

systemctl status firewalld

或

firewall-cmd --state

4. (可选)彻底不再使用 firewalld

systemctl mask firewalld

这会防止服务被意外启动


二、CentOS 6 及更早版本(使用 iptables)

停止 iptables

service iptables stop

禁止开机启动

chkconfig iptables off

三、如果你想“完全关闭防火墙功能”

如果你只是不想用 firewalld,也可以改用 iptables(不推荐新手):

systemctl stop firewalld
systemctl disable firewalld

⚠️ 生产环境不建议直接停用防火墙,可用:

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

四、确认是否已停用

systemctl is-enabled firewalld

返回 disabled 表示已停用


如果你能告诉我 CentOS 版本 和 使用场景(测试 / 生产),我可以给你更安全的建议。

0 踩