在 CentOS 中,防火墙主要使用 firewalld(CentOS 7 及以后)。下面按常见场景说明如何查看防火墙状态和规则。
systemctl status firewalld
或简看是否运行:
firewall-cmd --state
输出:
running:防火墙正在运行not running:未运行firewall-cmd --list-all
示例输出:
public (active)
services: ssh dhcpv6-client
ports: 80/tcp 3306/tcp
firewall-cmd --list-all --permanent
firewall-cmd --list-ports
firewall-cmd --list-services
firewall-cmd --query-port=80/tcp
firewall-cmd --get-active-zones
查看某 zone 的详细规则(如 public):
firewall-cmd --zone=public --list-all
CentOS 6 使用 iptables:
service iptables status
或查看规则:
iptables -L -n
systemctl start firewalld
systemctl stop firewalld
systemctl enable firewalld
如果你愿意,可以告诉我:
cat /etc/centos-release)我可以给你更精确的命令。