温馨提示×

Centos防火墙怎样关闭

小樊
78
2026-08-29 18:09:41
栏目: 智能运维

在 CentOS 中,防火墙服务通常是 firewalld(CentOS 7 及以后),也可能是 iptables(老版本)。下面分别说明如何关闭防火墙。


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

1️⃣ 查看防火墙状态

systemctl status firewalld

2️⃣ 临时关闭防火墙(重启后恢复)

systemctl stop firewalld

3️⃣ 永久关闭防火墙(开机不启动)

systemctl disable firewalld

✅ 验证是否已关闭:

systemctl status firewalld

显示为 inactive (dead) 即表示已关闭。


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

1️⃣ 关闭 iptables

service iptables stop

2️⃣ 永久关闭(开机不启动)

chkconfig iptables off

三、确认是否还有其他防火墙规则

关闭服务后,仍建议检查规则是否已清空:

iptables -L

如果还有规则,可清空(谨慎操作):

iptables -F

四、⚠️ 安全建议(重要)

  • 不建议在生产服务器直接关闭防火墙
  • 推荐做法:
    • 开放指定端口,而不是关闭防火墙
    • 例如开放 80 端口:
      firewall-cmd --permanent --add-port=80/tcp
      firewall-cmd --reload
      

如果你能告诉我:

  • CentOS 版本(执行 cat /etc/centos-release)
  • 是服务器还是本地虚拟机
  • 关闭防火墙的目的(测试 / 排错 / Docker / 端口无法访问)

我可以给你更合适、更安全的方案 ✅

0 踩