首页 > 编程知识 正文

dns清除缓存命令,DNS清除缓存

时间:2023-05-04 01:52:31 阅读:200601 作者:4940

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缓存

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。