如何清除 DNS 缓存(macOS、FreeBSD、Ubuntu、CentOS、Windows)

Unix Linux Windows 如何清除 DNS 缓存(macOS、FreeBSD、Ubuntu、CentOS、Windows)

Posted by sysin on 2021-07-03
Estimated Reading Time 2 Minutes
Words 533 In Total
更新日期:Sat Jul 03 2021 12:36:58 GMT+0800,阅读量:

请访问原文链接:如何清除 DNS 缓存(macOS、FreeBSD、Ubuntu、CentOS、Windows),查看最新版。原创作品,转载请保留出处。

作者主页:sysin.org


Flush DNS Cache on Ubuntu

1. Apple macOS

打开终端,输入如下命令:

1
sudo killall -HUP mDNSResponder; sudo dscacheutil -flushcache

参考:Reset the DNS cache in OS X

2. FreeBSD

FreeBSB 自带 nscd(Name Service Cache Daemon),默认没有启用。

运行如下命令启动 nscd 并设置为开机自动运行 (sysin):

1
sudo service nscd enable && sudo service nscd start

清除缓存即重启 nscd 服务:

1
sudo service nscd restart

3. Ubuntu

Ubuntu 默认运行 systemd-resolve daemon 用于名称服务缓存。

1
2
3
4
5
6
7
8
# Step 1. 查看 DNS 缓存状况
sudo systemd-resolve --statistics

# Step 2. 清除 DNS 缓存,systemd-resolve daemon 默认在所有的 Ubuntu 系统上运行
sudo systemd-resolve --flush-caches

# Step 3. 正在查看验证结果 (sysin)
sudo systemd-resolve --statistics

备注:Ubuntu 也可以配置使用 nscd。

4. CentOS

CentOS 默认不存在 Client 端的 DNS 缓存。

参看:

flush client dns cache

flush dns cache

通常使用 nscd 来启用 dns 缓存:

1
2
yum -y install nscd
systemctl enable --now nscd

清除缓存即重启 nscd 服务:

1
systemctl restart nscd

5. Microsoft Windows

清除 dns 缓存内容:

1
ipconfig/flushdns

查看 dns 缓存内容:

1
ipconfig/displaydns

Windows 下的 DNS Cache 是由 DNS Client 后台进程控制的,你可以在 “服务” 中将其关闭,这样 windows 就不会进行 DNS 缓存,每次都将直接查询 DNS Server。

附录:Linux 清除 DNS 缓存方法参考

Linux 可以运行 nscd 或者 BIND 或者 dnsmasq 作为名称服务缓存守护进程。

nscd

如果是清除 nscd 上的 Cache,可重新启动 nscd 服务来达成清除 DNS Cache 的效果:

1
2
3
service nscd restart
或是
service nscd reload

如果 nscd 无法执行,先安装 nscd,命令如下:sudo yum install nscd 或者 sudo apt install nscd

BIND

如果是清除 BIND 服务器上的 CACHE,用这个命令:

1
rndc flush

dnsmasq

如果你的 DNS 服务器是用 dnsmasq 实现的,用下面这个命令:

1
service dnsmasq restart

注:DNSmasq 是一个轻巧的,容易使用的 DNS 服务工具,它可以应用在内部网和 Internet 连接的时候的 IP 地址 NAT 转换,也可以用做小型网络的 DNS 服务。


☑️ 欢迎注册和留言,点击此处访问主站对应页面❗️


捐助本站 ❤️ Donate

点击访问官方网站


文章用于推荐和分享优秀的软件产品及其相关技术,所有软件默认提供官方原版(免费版或试用版),免费分享。对于部分产品笔者加入了自己的理解和分析,方便学习和测试使用。任何内容若侵犯了您的版权,请联系作者删除。如果您喜欢这篇文章或者觉得它对您有所帮助,或者发现有不当之处,欢迎您发表评论,也欢迎您分享这个网站,或者赞赏一下作者,谢谢!

支付宝赞赏 微信赞赏

赞赏一下