温馨提示×

centos防火墙怎么看状态

小樊
39
2026-10-05 19:25:19
栏目: 智能运维

在 CentOS 中查看防火墙状态,取决于你使用的防火墙管理工具(firewalld 或 iptables)。现在大多数 CentOS 7/8/Stream 默认使用 firewalld。


一、使用 firewalld(推荐,CentOS 7+ 默认)

1️⃣ 查看防火墙运行状态

systemctl status firewalld

或简写:

firewall-cmd --state

输出示例:

  • running → 防火墙正在运行
  • not running → 防火墙未运行

2️⃣ 查看防火墙是否开机自启

systemctl is-enabled firewalld
  • enabled → 开机自启
  • disabled → 不开机自启

二、使用 iptables(老版本或手动切换过)

查看 iptables 状态

service iptables status

或

systemctl status iptables

查看当前规则

iptables -L -n

三、常见组合检查(推荐)

# 查看 firewalld 状态
firewall-cmd --state

# 查看已开放端口
firewall-cmd --list-all

# 查看某个端口是否放行
firewall-cmd --query-port=80/tcp

四、如果防火墙没开怎么办?

启动防火墙:

systemctl start firewalld

开机自启:

systemctl enable firewalld

如果你告诉我 CentOS 版本号(如 7 / 8 / Stream),我可以给你更精确的命令。

0 踩