在 CentOS 中,防火墙一般有两种常见情况:CentOS 7 及以上默认使用 firewalld,老版本或手动装了 iptables。下面分别说明如何查看规则。
systemctl status firewalld
或
firewall-cmd --state
firewall-cmd --list-all
firewall-cmd --list-all --permanent
firewall-cmd --list-ports
firewall-cmd --list-services
firewall-cmd --zone=public --list-all
iptables -L -n -v
iptables -t nat -L -n -v
iptables -L -n -v --line-numbers
systemctl status firewalld
active (running) → 用的是 firewalldinactive 或 not found,再试:iptables -L
systemctl stop firewalld
systemctl disable firewalld
如果你能告诉我 CentOS 具体版本(如 7 / 8 / Stream),我可以给你更精确的命令示例。