How to flush DNS cache
This article explains how to clean your local DNS-cache. For performance reasons DNS record are cached locally to avoid the long DNS lookups for every download (image, css, js, html) from CNN. Instead your computer, laptop, tablet, smartphone and also your browser cache the DNS records. But what happens if your DNS record has changed, and the old one is cached?
Table of Contents
1. Basics around DNS (domain name system)
Some basics before we dig deeper into the topic how to flush the DNS.
1.1. DNS record
A DNS record maps a easy to understand name to a IP-address. E.g. www.cnn.com is much easier to remember as it's IP address 151.101.113.67.
1.2. DNS server or domain name server
DNS records are managed and serviced by the DNS server. DNS servers are also known as domain name server or sometimes even only name server.
1.3. DNS cache
A DNS record can now also be cached since you do not want to access every time you want to access a image, a css or a js file on CNN again and again a DNS server. This would slow down the browsing massively. So instead your computer, laptop, tablet, smartphone and also your browser cache the DNS records. Usually only that long as the TTL (time-to-live) of the DNS-record allows.
So far so good, but what happens, if your DNS record has changed, but your TTL is valid lets say for the next 3 days? Yes, you will get outdated responses and a wrong record from your cache? You need to flush your DNS cache, like you flush a toilet...
2. Flush DNS cache on windows
Type keys Windows + R to open the run prompt.
enter
cmd
and type Ctrl + Shift + Enter key to run the command line as administrator.
now enter
ipconfig /flushdns
and your DNS cache is flushed.
Maybe you want to see the cached DNS records, in this case enter
ipconfig /displaydns
3. Flush DNS cache on Ubuntu
On Ubuntu it is a bit trickier, since the last years the networking has changed a lot. So you have to try this commands.
Note: not all commands may work for you, depending on what you have already installed.
This is the most probable, which shall work for you:
sudo /etc/init.d/dns-clean restart
If this does not work well, and you still resolv the old value, try this:
sudo /etc/init.d/networking force-reload
maybe also this:
sudo /etc/init.d/nscd restart
and maybe this:
sudo service network-manager restart
and the final option
sudo systemd-resolve --flush-caches
4. Local DNS cache flushed but resolving old IP
The most common case is, that your upstream DNS-servers are holding the outdated DNS record. To try if this is the case try:
nslookup
server 8.8.8.8
www.cnn.com
This will tell your nslookup tool not to use your upstream DNS server and instead to use google's DNS server (8.8.8.8).
If you now still get the outdated DNS record, maybe your DNS entry is invalid, or you need to wait a while.
If your new DNS record shows up, you are fine. Now you need to flush the DNS cache of your upstream DNS servers. This are typically:
- your router
the easiest way is typically to restart your device - your ISP DNS server
here you only can try to reach out to your ISP, or you configure your router to temporarily use google's DNS server 8.8.8.8
5. Conclusion
In this article we focused on the basics of DNS caching and how you can get rid of outdated DNS cache.