温馨提示×

如何查看CentOS防火墙

小樊
50
2026-08-18 14:47:43
栏目: 智能运维

在 CentOS 中,防火墙的查看方式取决于系统使用的防火墙服务。CentOS 7 及以后默认使用 firewalld,而 CentOS 6 及更早版本使用 iptables。下面分别说明。


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

1. 查看防火墙状态

systemctl status firewalld

firewall-cmd --state

2. 查看当前活动区域及规则

firewall-cmd --list-all

示例输出:

public (active)
  target: default
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client
  ports:
  protocols:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

3. 查看所有区域的配置

firewall-cmd --list-all-zones

4. 查看已放行的服务

firewall-cmd --list-services

5. 查看已放行的端口

firewall-cmd --list-ports

6. 查看是否开机自启

systemctl is-enabled firewalld

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

1. 查看防火墙状态

service iptables status

2. 查看 iptables 规则

iptables -L -n -v

3. 查看 NAT 表(如做了端口映射)

iptables -t nat -L -n -v

三、判断当前系统使用哪种防火墙

systemctl status firewalld
  • 如果显示 active (running) → 使用 firewalld
  • 如果提示 not foundinactive,再看:
systemctl status iptables

四、常见补充操作

临时关闭防火墙(不推荐长期使用)

systemctl stop firewalld

永久关闭防火墙

systemctl disable firewalld

重新加载防火墙规则

firewall-cmd --reload

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

  • ✅ CentOS 具体版本(cat /etc/centos-release
  • ✅ 是查看端口、服务,还是排查访问不通的问题

我可以给你更精确的命令或排错步骤。

0