Disclaimer: Affiliate links help us produce good content. Learn more.
A Domain Name System (DNS) cache remembers the websites you visit so you can load them faster in the future. Sounds good, right? But there are times when you will want to flush your DNS cache and remove this trail.
DNS is essentially the internet directory. When looking at how to flush DNS, it is important to know what is DNS cache. When you access a domain name for the first time, your computer does a DNS request to a server.
You have likely encountered a “time-out” or “DNS server cannot be reached” error message when trying to visit a site that you previously visited.
When you looked at the problem, there was nothing wrong with the internet connection, and upon visiting other sites, you got the same error message. This can happen when the server cannot identify the IP address that it allocated to the website and sends to your device. A DNS identifies a domain name and allocates it an IP address so that when you visit that website in the future it can retrieve the identification number on your computer and then match it to the website. This allows for easy access to the site.
What is a DNS Cache?
A DNS cache (sometimes called a “resolver cache”) is a temporary database of all your recent website visits. It also includes attempted visits to websites. This database is stored on your device and is maintained by the device’s operating system. The operating system uses this memory of DNS lookups to quickly load a website.
The function of a DNS cache is to keep an index of all websites along with their corresponding IP addresses. Like the contact list on your phone that allows you to easily look up a specific person and call them up.
A DNS cache is used so that you don’t have to memorize the IP address for every website.
Sometimes for privacy or technical reasons you’ll want to erase your DNS cache. To do this, you need to use the flush DNS command.
How does DNS cache work?
- The first time you type in a URL like “www.google.com” your device’s web browser asks the router for an IP address for that website.
- The router then asks a DNS server for the IP address of the URL. Once the DNS server finds the corresponding IP address, it can return the page information to the router.
- The router sends the information to your web browser. Now the web browser can display the information for “www.google.com.”
- The URL and corresponding IP address is now stored in the DNS cache on your computer so the next time you type “www.google.com” into your web browser, it can quickly display the corresponding page, since your router no longer has to ask the DNS server for the IP address.
It’s like asking your friend for someone’s phone number. Once you put the phone number in your contact list, you never have to ask your friend for that person’s phone number again.
In the same way you have a phone number for each person in your contact list, the DNS cache on your computer holds the number corresponding to each website you visit.
The different levels of DNS caching
When accessing a website using its URL or domain name, your computer first tries to look up their IP addresses within the DNS cache database before the browser issues the request to your router.
In the DNS cache database, there is a list comprising all domain names you have visited in the recent past and the addresses that DNS allocated them when you first made a request. DNS caching doesn’t only happen at the browser and operating system levels. In a new DNS lookup, the process involves checking in the resolver, the root server, and the TLD server. In each of these steps, there is information that is gathered and then cached or stored for later reference or use. What this means is that if the local DNS database or DNS cache is empty, it is possible that the resolver has a cached copy of the same information. This ensures that the DNS lookup process doesn’t start afresh. You can flush DNS cache at different levels.
What is DNS cache poisoning?
A DNS cache is polluted or poisoned when you have unauthorized domain names or IPs being inserted into it.
This poisoning is most often associated with infections by computer viruses, malware or network attacks that put in invalid DNS entries within the cache database. Occasionally, DNS poisoning can occur when it is corrupted because of administrative accidents or technical glitches.
When there is DNS poisoning, it redirects client or browser requests to destinations that are wrong and most likely, these destinations are malicious websites or sites full of advertisements. If an attacker, for example, redirects the requests for www.gmail.com to a website disguised as a Gmail website, you could end up experiencing a phishing attack. When you have internet connectivity issues with your computer or you are trying to troubleshoot a cache poisoning issue, you can consider flushing a DNS cache to erase, reset, or clear the database. You can flush DNS Mac or Windows caches if they are poisoned.
Why should you flush DNS cache?
Flushing erases all the entries in the cache database. It removes any invalid records that may be present in the DNS database. This forces your device to again send a request to your router to ask the DNS server that your network has been setup to use to lookup the IP address the next time you visit these websites. The database will be repopulated with the IP addresses.
There are many reasons why you would want to flush DNS.
- You may want to remove your browsing history since anyone having access to your device is able to check the DNS cache and find out what websites you visited recently.
- You may want to solve issues of bad connections. If you had a virus or malware that inserted invalid IP entries into your computer, you can do away with them by flushing DNS.
- Flushing the DNS cache can resolve stale content issue if, for example, a website moves to a different server.
How to flush DNS on Windows OS
Before you flush DNS in Windows, you need to close web browsers and applications that are open on your computer.
- Open your Windows command prompt by tapping Windows and “R” or by selecting the “Start” menu then entering “cmd” within the search text field.
- Then click the “Enter” key on the keyboard. In the command prompt, you enter “ipconfig /flushdns” and then press “Enter” key again. Shortly, you will see Windows displaying a message like this “Successfully flushed the DNS Resolver Cache.” When the message is displayed, it means that DNS has been flushed and all entries have been erased.
- You can check the DNS resolver cache to see if there are any entries or IPs by entering “ipconfig /displaydns” within the command prompt and then clicking the “Enter” key on your keyboard. This will allow you to confirm that the entries on the DNS cache have actually been deleted or flushed out. If it’s a Linux flush DNS process, it will also be different.
How to flush DNS on Mac OS
Flushing DNS cache on a Mac operating system largely depends on the version of the OS you have installed in your computer. There will be some slight differences with the commands you have to enter to flush DNS. To flush the DNS entries, you have to close the browser and exit other applications that are running.
- Open your computer’s terminal window.
- If your computer is running on Lion (Mac OS X 10.5, 10.6, or 10.7), you will enter this command “dscacheutil –flushcache” and then press the “Return” key.
- If you are using Mac OS X 10.4 Tiger, you will need to enter this command “lookupd –flushcache” and then press “Return” key.
- If you are using Mac OS X Snow Leopard, you use this command “sudo dscacheutil –flushcache”.
- For Mac OS X Yosemite and later versions, you can use the command “sudo discoveryutil udnsflushcaches.”
It is also possible for you to erase the cache on a browser, for example, by using Chrome flush DNS process.
How to flush DNS cache on Linux
If you use a Linux operating system, the “NSCD daemon” helps manage the DNS cache. Usually, restarting the NSCD daemon can flush the DNS cache. There are other Linux builds that run on BIND or DNSMASQ. To flush DNS on these builds, you will use different commands.
- For example, to flush NSCD DNS cache, you will need to enter “$sudo/etc/init.d/nscd restart” and then press the “Enter” or “Return” key. When the NSCD restarts, the DNS is flushed. You can also enter this command “# service nscd restart” it will work the same way.
- If you want to flush DNSMASQ DNS cache, you will use the command “$sudo/etc/init.d/dnsmasq restart” and then press “Return” or “Enter” key. When DNSMASQ restarts, you will have the DNS flushed.
- Similarly, if you want to flush DNS in BIND, you will enter “#/etc/init.d/named restart” and then press “Enter” or “Return” key. After BIND restarts, the DNS will be deleted.
So, why flush DNS for Linux? It will clear old or corrupted caches and speed up your Linux computer.
How to flush DNS on iOS and Android
There are two options you can use to clear DNS cache within iOS devices. One is rebooting your iOS device and the second is switching the device to flight mode. On the iOS device, switching to Airplane Mode will completely disable the entire network connectivity until you turn it off. This will flush the DNS. So, to perform this process:
- Go to “Settings” on your device and then turn on Airplane Mode.
- You can also flush DNS on iOS by restarting your Wi-Fi connection. Just close the app completely and ensure it isn’t running in background mode. Switch off the Wi-Fi on your device and then turn it on. Now open the app, you will have cleared DNS cache.
So, what does flush DNS do for your mobile phone? It helps ensure security and do away with corrupted, changed, or bad caches.
How to flush DNS on Android
In operating systems like Windows and Linux or Mac, we use terminal windows to help clear DNS cache. However, when it comes to Android devices, there is usually no terminal. That said, it is also easy to flush DNS caches on devices running Android (it’s very similar to iOS devices). You do this by restarting the Wi-Fi.
- First, close the apps and ensure you don’t have any that are running on background mode.
- Next, restart the Wi-Fi by turning it off and then turning it on within your device. In case you do not want to have the Wi-Fi disconnected, you can consider clearing the cache within the individual apps for example, on the Chrome browser
- To do that you will have to go to “Settings” then to “Apps” and then look for the app that you want to flush DNS caches. Next, you go to “Storage” and then tap on the button that says, “Clear Cache”.
That’s how to flush your DNS on Android mobile devices.
Flushing DNS cache in Chrome
In order to flush DNS on Google Chrome:
- First, you will have to type “chrome://net-internals/#DNS” within the search bar.
- Next, click the button on “Clear Host Cache.” You can see the domain names that are in the cache database within the bar located at the top section of the screen. It is usually next to “Capturing Events.”
When you have cleared the cache in Chrome, you will see that the number of domain names will change to zero. You can clear both DNS cache and Sockets so that you remove any packets that may be lingering. Click the “Down Arrow” within the area on the upper right corner of the browser. This arrow provides you with an alternative to using the “Clear Host Cache Button.” To clear both Sockets and DNS cache, you will have to select “Clear Cache” and “Flush Sockets.” Remember that you will need to open the menu again because it closes when you select one. That is how to do a DNS flush in Chrome.
Flushing DNS cache in Firefox
To delete DNS cache in Firefox:
- First, you need to click the “Hamburger” menu found within the upper right corner of the browser
- This will take you to the main menu where you click the “Settings.”
- Next, select “Privacy” and then select “Clear Now.”
You can also find a checkbox that you can select if you need to delete your browsing history whenever you exit Firefox.
Flushing DNS cache in Opera
If you are using Opera as your browser, there are steps to clear DNS caches.
- First, click on the Opera icon found at the bottom of the browser
- You then go to “Clear Browsing Data” which is found in the “Settings” menu. After clicking that button, the browser will clear all caches.
You can see that depending on the kind of browser you use, there are different ways of clearing cache. So, what happens when you flush DNS in a browser?
When you delete caches on browsers, it can help prevent any malicious activities and improves the performance of the browsers.
Checking DNS caches on your device
Sometimes, there may be situations of flush DNS not working. You can find out if you have actually deleted DNS cache on your OS. The process will vary based on which OS system you are using.
- For Windows OS, you can check DNS caches entries by opening the command prompt and then entering this command “ipconfig /displaydns.” This will display the cache entries.
- On a Mac OS, the process for checking DNS cache is a bit different. You will have to start by opening the Console app and then selecting your device on the left sidebar by entering this command “any:mdnsresponder” in the search bar.
- After that, you open the command line, then enter this command “sudo killall -INFO mDNSResponder.” When you go back to the Console app, you will be able to see the cached DNS entries. If you did flush DNS caches successfully, you won’t be able to see any entries within the list.
Erasing DNS caches can help with many issues as it can make the computer to be faster. However, it makes the internet run slower.
One thing to understand is that cache contains parts of websites that are static. They may be anything from HTML files to graphics, to CSS style sheets. Your cache holds such items so that when you visit a website, particularly the ones you regularly visit, your device will only have to download the parts of the websites that are different or new.
The old parts, which have not changed are usually retrieved from your device’s cache. So, you will use less bandwidth in downloading the website. It will also appear on the screen faster. When you continuously delete your cache, it means your computer will have to begin from scratch every time you are visiting a website, and this includes websites that you access frequently. These are things you need to know before you flush DNS.
Disclaimer: Affiliate links help us produce good content. Learn more.