ubuntu清除dns缓存

Whenever we try to access a website, a DNS name resolution query is executed to resolve its IP address. The operating systems cache this data to avoid reaching out to name servers every time.

每当我们尝试访问网站时,都会执行DNS名称解析查询来解析其IP地址。 操作系统缓存此数据,以避免每次都与名称服务器联系。

为什么要清除DNS缓存? (Why to Clear DNS Cache?)

Sometimes a website IP address is changed when it’s moved to another server. In that case, if we hit the cached IP address, the website won’t work.

有时,网站的IP地址在移至另一台服务器时会更改。 在这种情况下,如果我们点击了缓存的IP地址,则该网站将无法正常运行。

DNS entries have the “Time To Live (TTL)” value associated with it, which tells the Operating System name resolution service when to invalidate the DNS Cache.

DNS条目具有与之关联的“生存时间(TTL)”值,该值告诉操作系统名称解析服务何时使DNS缓存无效。

But, if you want to reach out to the new IP address before TTL expires, the only solution is to flush the DNS cache.

但是,如果您想在TTL过期之前联系到新的IP地址,则唯一的解决方案是刷新DNS缓存。

Ubuntu服务进行DNS名称解析 (Ubuntu Service for DNS Name Resolution)

The systemd-resolved.service is used to run the DNS queries and maintain the DNS Cache.

systemd-resolved.service用于运行DNS查询和维护DNS缓存。

We can use the following command to check its status.

我们可以使用以下命令来检查其状态。


# sudo systemctl status systemd-resolved
Ubuntu systemd-resolved.service Status
Ubuntu systemd-resolved.service状态

We can run the following command to check the DNS Cache statistics.

我们可以运行以下命令来检查DNS缓存统计信息。


# sudo systemd-resolve --statistics
Ubuntu Dns Cache Statistics
Ubuntu Dns缓存统计信息

There is a slight difference in the service and command name. The command name doesn’t have the last character “d”.

服务和命令名称略有不同。 命令名称没有最后一个字符“ d”。

如何在Ubuntu上清除DNS缓存? (How to Clear DNS Cache on Ubuntu?)

We can run the following command to clear the DNS cache on Ubuntu.

我们可以运行以下命令来清除Ubuntu上的DNS缓存。


# sudo systemd-resolve --flush-caches

Then, check the statistics again to confirm that the “Current Cache Size” is 0.

然后,再次检查统计信息以确认“当前缓存大小”为0。

Ubuntu Dns Flush Cache
Ubuntu Dns刷新缓存

重新启动systemd解析的服务以清除所有DNS缓存统计信息 (Restarting systemd-resolved service to clear all DNS Cache Statistics)

The DNS flush command doesn’t clear the cache hits and misses statistics. If you want to clear all the Cache stats, then you have to restart the systemd-resolved service.

DNS刷新命令不会清除缓存命中和未命中统计信息。 如果要清除所有缓存统计信息,则必须重新启动systemd解析的服务。


# sudo systemctl restart systemd-resolved
Ubuntu Restart Systemd Resolved Service
Ubuntu重新启动Systemd解决的服务

结论 (Conclusion)

It’s very easy to flush cache on Ubuntu. The command to flush the DNS can be run by the root user or a user with sudo privileges.

在Ubuntu上刷新缓存非常容易。 刷新DNS的命令可以由root用户或具有sudo特权的用户运行。

翻译自: https://www.journaldev.com/40077/ubuntu-clear-dns-cache

ubuntu清除dns缓存

ubuntu清除dns缓存_如何在Ubuntu上清除DNS缓存相关推荐

  1. macos 清空dns缓存_如何在macOS上重置DNS缓存

    macos 清空dns缓存 If you work on websites, you'll occasionally need to reset your computer's DNS cache, ...

  2. ubuntu 局域网dns服务器_如何在 Ubuntu 16.04 服务器上配置内网 DNS 服务

    DNS 1. 简介 本文使用 BIND9,用尽量少的步骤,搭建出一个可用的内网 DNS 服务.另外要说明的一点是,本文不仅适用于 Ubuntu 16.04,也使用其后的 Ubuntu 系统(截止到目前 ...

  3. ubuntu的web服务器_如何在Ubuntu上安装OpenLiteSpeed Web服务器?

    ubuntu的web服务器 Want to install OpenLiteSpeed Webserver on Ubuntu? Today we're going to do just that. ...

  4. ubuntu安装zlib库_如何在Ubuntu中安装zlib库?

    ubuntu安装zlib库 On Ubuntu (18.04), installing zlib reported unable to locate package zlib: 在Ubuntu(18. ...

  5. windows7安dns服务器_在Windows 7 上安装DNS服务器bind9方法详解

    本文主要介绍在WIN7上安装bind9 DNS服务器的方法,非常详细希望对大家有所帮助 本文主要介绍在WIN7上利用ntbind部署DNS服务器的方法.ntbind是Bind的Windows版本, 1 ...

  6. ubuntu安装python百度经验_如何在Ubuntu 20.04上安装Python 3.9(含python编译安装和使用Apt命令安装)...

    在本文中,我们将向您展示在Ubuntu 20.04上安装Python 3.9的两种方法.第一种使用APT命令安装Python3.9,第二种是在Ubuntu20.04上编译安装Python 3.9.本教 ...

  7. ubuntu取消主目录加密_如何在Ubuntu上恢复加密的主目录

    ubuntu取消主目录加密 Access an encrypted home directory when you're not logged in – say, from a live CD – a ...

  8. ubuntu软件包降级命令_如何在Ubuntu上降级软件包

    ubuntu软件包降级命令 Ubuntu's Update Manager keeps your packages at the latest version, but occasionally a ...

  9. ubuntu 多指触摸_如何在Ubuntu上交换两指和三指触摸板轻按操作

    ubuntu 多指触摸 By default, Ubuntu uses a two-finger tap for right-click and a three-finger tap for midd ...

  10. ubuntu java 关闭进程_如何在Ubuntu中关闭Tomcat?

    问题描述 我试图关闭tomcat,如下所示,但是tomcat似乎仍在运行(http://localhost:8080 /) vandegraff@vandegraff-laptop:~$ /usr/s ...

最新文章

  1. Spring Cloud Alibaba基础教程:Nacos配置的多文件加载与共享配置
  2. visio思维导图模板_如何下载思维导图模板?在线教你找精美漂亮的思维导图
  3. 《CLR via C#》读书笔记 之 参数
  4. IDEA工具开发必备设置-极大提高开发效率
  5. 宁德时代预计一季度净利润超9.9亿元 同比增长超140%
  6. discuz点歌台插件
  7. c++程序员面试宝典
  8. 导航网/广告位/导航分类/可运营
  9. 用计算机控制人造卫星和导弹发射,用计算机控制人造卫星和导弹的发射,按计算机应用的分类,它应属于什么...
  10. 曼昆经济学原理读书笔记加杂感(一)
  11. 树的基本概念及表示方法
  12. 如何查SCI期刊的影响因子与排名
  13. 【论文写作】本科、硕士研究生毕业论文字体、段落格式参考
  14. 在线超级计算器(微积分、方程)
  15. Tableau图表 | 6、气泡图/树状图/文字云
  16. 12 投资心理建设宝典
  17. python笔记---(实验二)
  18. TridentNet
  19. 乐鑫嵌入式笔试总结-提前批
  20. iOS - 使用自定义字体-苹方字体

热门文章

  1. matlab怎么画函数线,请问matlab怎么画常数函数,比如同时画x=300和x=400这两条线...
  2. python求梅森尼数_梅森尼数 - 寂寞暴走伤的个人空间 - OSCHINA - 中文开源技术交流社区...
  3. C++ SLT中的容器学习与函数谓词
  4. 巴马冷泉、巴马水到底是个什么?有市场吗?
  5. java 实现html压缩
  6. 股票预测和股票分析就用FineBI!
  7. 使用计算机配置路由器,电脑设置路由器步骤
  8. No version of NDK matched the requested version xxx 问题解决
  9. html5弹幕制作(探索ing)
  10. 执行linux操作时提示:权限不够