用 `resolvectl flush-caches` 清除 DNS 缓存

在基于 systemd 的 Linux(Ubuntu、Fedora、Debian 12+)上,本地 DNS 缓存由 systemd-resolved 管理——清缓存命令从旧的 systemd-resolve 改名后,很多人总想不起来。

Linux缓存systemd-resolved DNS 解析DNS故障排查低风险
运行 `resolvectl flush-caches` 立即清空 systemd-resolved 的全部 DNS 缓存,可用 `resolvectl statistics` 验证。

01命令

命令
$ resolvectl flush-caches

02作用说明

systemd-resolved 会在本地缓存所有 DNS 应答,所以修改了 DNS 记录或切换网络后,你可能仍解析到旧 IP。`resolvectl flush-caches` 会立刻丢弃全部缓存条目(旧版本系统对应 `systemd-resolve --flush-caches`)。由于只是丢弃缓存,这条命令可以放心反复执行。

03风险

风险低风险
使用条件Requires systemd-resolved (default on Ubuntu, Fedora and most modern systemd distros)

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • resolvectl(1) — Linux manual page
    man7.org · technical · 2026-09-17
    依据: Documents `resolvectl flush-caches` which flushes all DNS caches of systemd-resolved, and `resolvectl statistics` to view cache size

最后验证: 2026-09-17 · 分类: 网络

06相关方案