温馨提示×

centos防火墙怎么查看

小樊
38
2026-07-20 02:00:50
栏目: 智能运维

CentOS 上查看防火墙状态,取决于你使用的是 firewalld 还是 iptables。下面分别说明(CentOS 7/8/9 默认是 firewalld)。


一、查看 firewalld 防火墙(最常见)

1️⃣ 查看防火墙状态

systemctl status firewalld

firewall-cmd --state

输出示例:

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

2️⃣ 查看当前活动区域和规则

firewall-cmd --list-all

输出示例:

public (active)
  target: default
  interfaces: eth0
  services: ssh dhcpv6-client
  ports: 8080/tcp

3️⃣ 查看所有开放端口

firewall-cmd --list-ports

4️⃣ 查看所有允许的服务

firewall-cmd --list-services

5️⃣ 查看所有区域

firewall-cmd --get-zones

6️⃣ 查看指定区域(如 public)

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

二、查看 iptables 防火墙(老版本或手动关闭 firewalld)

1️⃣ 查看 iptables 规则

iptables -L -n -v

2️⃣ 查看 NAT 表

iptables -t nat -L -n -v

三、判断系统用的是哪种防火墙

✅ 查看 firewalld 是否运行

systemctl status firewalld

✅ 查看 iptables 服务是否运行

systemctl status iptables

⚠️ 同时启用 firewalld 和 iptables 容易冲突,不建议。


四、快速查看总结(推荐用这个)

firewall-cmd --state && firewall-cmd --list-all

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

  • CentOS 版本(cat /etc/centos-release
  • 是服务器还是本地虚拟机
  • 想排查的是 端口不通 / 无法访问 / 安全加固

我可以帮你具体分析 ✅

0