温馨提示×

怎样清除ubuntudns缓存

小樊
45
2026-10-03 21:26:01
栏目: 智能运维

在 Ubuntu 上清除 DNS 缓存的方法,取决于你系统使用的是哪种 DNS 解析服务。常见情况如下:


一、使用 systemd-resolved(Ubuntu 17.04+ 默认)

大多数现代 Ubuntu 使用 systemd-resolved。

查看 DNS 服务状态

systemctl status systemd-resolved

清除 DNS 缓存

sudo systemd-resolve --flush-caches

或在较新版本中:

sudo resolvectl flush-caches

验证缓存已清空

sudo systemd-resolve --statistics

或

resolvectl statistics

看 Cache Size 是否变为 0。


二、使用 nscd(较少见)

如果你安装了 nscd:

sudo systemctl restart nscd

或

sudo service nscd restart

三、使用 dnsmasq(如 NetworkManager 或路由器场景)

如果是本地 dnsmasq:

sudo systemctl restart dnsmasq

如果是 NetworkManager 自带的 dnsmasq:

sudo systemctl restart NetworkManager

四、使用 BIND(自建 DNS 服务器,少见)

sudo rndc flush

五、浏览器 DNS 缓存(容易被忽略)

系统缓存清了,但浏览器仍有缓存:

  • Chrome:chrome://net-internals/#dns → Clear host cache
  • Firefox:重启浏览器

快速判断你用的是什么

cat /etc/resolv.conf

若看到:

nameserver 127.0.0.53

说明是 systemd-resolved。


如果你告诉我 Ubuntu 版本 或 systemctl status systemd-resolved 的输出,我可以给你更精确的建议。

0 踩