温馨提示×

如何查看Debian防火墙

小樊
39
2026-07-18 05:19:29
栏目: 智能运维

在 Debian 系统中,查看防火墙状态取决于你使用的是哪种防火墙工具。Debian 默认没有启用防火墙,常见的是使用 UFWiptables / nftables。下面按常见情况说明。


一、查看是否安装了防火墙工具

1️⃣ 查看是否安装 UFW

ufw status

常见输出:

  • Status: active → 防火墙已启用
  • Status: inactive → 防火墙未启用
  • ufw: command not found → 未安装 UFW

如果未安装:

sudo apt update
sudo apt install ufw

二、使用 UFW(推荐,最简单)

查看防火墙状态和规则

sudo ufw status verbose

示例输出:

Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing)
New profiles: skip

查看详细规则

sudo ufw status numbered

三、查看 iptables(传统方式)

查看当前规则

sudo iptables -L -n -v

常见链:

  • INPUT:进入流量
  • OUTPUT:发出流量
  • FORWARD:转发流量

如果输出很少,说明基本没有规则(不等于“关闭防火墙”,而是放行所有流量)。


四、查看 nftables(Debian 10+ 推荐)

Debian 新版中,iptables 实际可能是 nftables 的兼容层。

查看 nftables 规则

sudo nft list ruleset
  • 如果输出为空 → 没有防火墙规则
  • 有内容 → 表示有防火墙策略

五、查看系统是否启用了防火墙服务

查看 UFW 服务状态

systemctl status ufw

查看 nftables 服务状态

systemctl status nftables

六、快速判断当前防火墙情况(推荐)

最常用组合命令:

sudo ufw status
sudo iptables -L
sudo nft list ruleset

七、常见结论说明

情况 含义
三条命令都无输出 Debian 默认无防火墙
ufw active 正在使用 UFW
iptables 有规则 手动配置过防火墙
nftables 有规则 新系统防火墙

八、如果你愿意,我可以帮你:

  • ✅ 判断你当前系统是否“安全”
  • ✅ 推荐 Debian 最佳防火墙配置
  • ✅ 教你怎么开放 / 关闭端口
  • ✅ 排查端口无法访问问题

你可以直接把下面命令的输出贴出来:

sudo ufw status
sudo iptables -L

0