在 Debian 系统中,查看防火墙状态主要取决于你使用的防火墙管理工具。目前最常见的是 UFW(简单防火墙)和 nftables/iptables。以下是针对每种情况的查看方法:
Debian 默认可能没有安装 UFW,但它是管理防火墙最简便的方式。
查看 UFW 状态:
sudo ufw status
Status: inactive,表示防火墙已关闭。Status: active,表示防火墙正在运行,并会列出允许/拒绝的规则。查看详细状态(显示规则对应的端口号):
sudo ufw status verbose
查看已加载的规则(原始格式):
sudo ufw status numbered
现代 Debian 系统底层通常使用 nftables。
查看 nftables 规则(当前生效的配置):
sudo nft list ruleset
如果输出为空,通常表示没有配置防火墙规则(或者处于全通状态)。
检查 nftables 服务状态:
sudo systemctl status nftables
这会告诉你 nftables 服务是否正在运行,以及启动时是否加载了配置。
虽然较新的系统使用 nftables,但 iptables 命令仍然可用(通常作为 nftables 的兼容层)。
查看 IPv4 防火墙规则:
sudo iptables -L -v -n
-L: 列出规则。-v: 显示详细信息(流量计数等)。-n: 数字格式显示(不解析域名,速度更快)。查看 IPv6 防火墙规则:
sudo ip6tables -L -v -n
检查 iptables 服务状态(如果使用 iptables-persistent):
sudo systemctl status netfilter-persistent
# 或者
sudo systemctl status iptables
先输入 sudo ufw status。
Status: active 或 inactive,说明你用的是 UFW。sudo: ufw: command not found,说明没装 UFW,继续下一步。输入 sudo systemctl status nftables。
active (exited) 或 loaded,说明你用的是 nftables。Unit nftables.service could not be found,继续下一步。输入 sudo iptables -L。
建议: 对于大多数 Debian 桌面用户或新手,推荐使用 UFW,因为它命令简单直观。如果你发现系统没有安装,可以通过以下命令安装:
sudo apt update
sudo apt install ufw