温馨提示×

如何关闭CentOS防火墙

小樊
34
2026-07-08 06:48:06
栏目: 智能运维

在 CentOS 中,防火墙服务通常是 firewalld(CentOS 7 及以后版本)。下面按不同版本和需求说明如何关闭防火墙。


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

1. 查看防火墙状态

sudo systemctl status firewalld

2. 临时关闭防火墙(重启后失效)

sudo systemctl stop firewalld

3. 永久关闭防火墙(重启后仍关闭)

sudo systemctl disable firewalld

4. 同时停止并禁用(常用)

sudo systemctl stop firewalld
sudo systemctl disable firewalld

5. 验证是否已关闭

sudo systemctl status firewalld

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


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

1. 关闭 iptables

sudo service iptables stop

2. 永久关闭

sudo chkconfig iptables off

三、只开放端口(不推荐直接关闭防火墙)

如果你是为了让某个服务(如 80、3306、22)可访问,更安全的方式是开放端口而不是关闭防火墙

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

查看已开放端口:

sudo firewall-cmd --list-ports

四、安全建议(重要)

不建议在生产环境直接关闭防火墙
✅ 若是测试环境或内网,可临时关闭
✅ 云服务器还需检查 安全组 / ACL


如果你愿意,可以告诉我:

  • CentOS 具体版本(cat /etc/centos-release
  • 是本地虚拟机、物理机还是云服务器

我可以给你更精确、安全的操作方案。

0