温馨提示×

centos防火墙怎样查看

小樊
58
2026-09-02 19:34:12
栏目: 智能运维

在 CentOS 中,查看防火墙状态和方法取决于系统版本(CentOS 7 及以上默认使用 firewalldCentOS 6 及更早使用 iptables)。


一、CentOS 7 / 8 / Stream(firewalld)

1️⃣ 查看防火墙状态

systemctl status firewalld

firewall-cmd --state

输出:

  • running:防火墙已开启
  • not running:防火墙未运行

2️⃣ 查看已开放的端口

firewall-cmd --list-ports

3️⃣ 查看所有防火墙规则

firewall-cmd --list-all

4️⃣ 查看某个 zone 的规则(如 public)

firewall-cmd --zone=public --list-all

5️⃣ 查看是否开机自启

systemctl is-enabled firewalld

二、CentOS 6 或更早(iptables)

1️⃣ 查看防火墙状态

service iptables status

2️⃣ 查看规则

iptables -L -n -v

3️⃣ 查看是否开机启动

chkconfig --list iptables

三、通用:检查端口是否监听

netstat -tunlp

ss -tunlp

四、常见示例

  • 查看 80 端口是否放行:
firewall-cmd --query-port=80/tcp

如果你能告诉我 CentOS 版本具体想查什么(端口 / 规则 / 状态),我可以给你更精确的命令。

0