How to Flush DNS Cache in macOS, Windows, & Linux?


Introduction

In today's world, the internet has become an indispensable part of our daily lives. We rely on it for everything from work to entertainment, and every website we visit is identified by its unique IP address. However, remembering these IP addresses would be difficult, if not impossible.

This is where the Domain Name System (DNS) comes in. It translates these numerical IP addresses into readable domain names that are easy to remember.

Explanation of DNS Cache

When a computer or device connects to the internet or a network, it saves a copy of the DNS information in its memory cache called the DNS cache. The purpose of this cache is to speed up future requests for the same domain name and reduce network traffic by avoiding repeated lookups.

The DNS cache stores information like domain names, their corresponding IP addresses, and other related data that was previously requested by the user.

Importance of Flushing DNS Cache

As useful as this system is, sometimes cached information can become outdated or corrupted which can cause problems for users trying to connect to websites or networks. For example, if you are trying to access a website that has recently changed its hosting provider and updated its IP address but your system still holds onto its old address information in your DNS cache then you will not be able to access that website.

How to Flush DNS Cache in macOS

Using Terminal Command

Flushing the DNS cache on macOS using terminal commands is a simple and effective way to clear any stale DNS entries. Here are the step-by-step instructions for flushing your DNS cache via the terminal command line.

  • Open up the Terminal application from your applications folder, or by searching for it in Spotlight.

  • Type in the following command: sudo killall -HUP mDNSResponder

  • Press Enter and type in your admin password when prompted.

  • Once you have entered your admin password, press Enter again. That's it!

You have successfully flushed your DNS cache using Terminal on macOS.

Using System Preferences

Alternatively, macOS users can also flush their DNS cache through System Preferences.

  • Open up System Preferences from the Apple menu or by searching for it in Spotlight.

  • Go to Network > Advanced > DNS > Click "DNS" tab

  • vClick "minus" (-) button In front of IP addresses under "DNS Servers"

  • Finally click "Apply" and then "OK"

That's it! You have successfully flushed your DNS cache through system preferences on macOs. Screenshots for visual aid −

How to Flush DNS Cache in Windows

Using Command Prompt

One of the most common ways to flush DNS cache in Windows is by utilizing Command Prompt. To do this, simply follow these step-by-step instructions −

  • Click on the Start Menu icon in the bottom-left corner of your screen.

  • Type "cmd" into the search bar.

  • Right-click on "Command Prompt" and select "Run as administrator".

  • Type "ipconfig /flushdns" into the Command Prompt and press Enter.

  • You should see a message confirming that your DNS cache has been successfully flushed.

To ensure that you have properly flushed your DNS cache, it can be helpful to check it using the ipconfig command. Simply type "ipconfig /displaydns" into Command Prompt after flushing your cache, and you should see an empty list indicating that your DNS cache has been cleared.

Using PowerShell

Another way to flush DNS cache in Windows is by using PowerShell. While this method may be less commonly used than using Command Prompt, it can still be a helpful alternative for some users.

Follow these simple steps −

  • Click on the Start Menu icon in the bottom-left corner of your screen.

  • Type "powershell" into the search bar.

  • Right-click on "Windows PowerShell" and select "Run as administrator".

  • Type "Clear-DnsClientCache" into PowerShell and press Enter.

  • You should see a message confirming that your DNS cache has been successfully cleared.

As with flushing through Command Prompt, you can use PowerShell to check whether or not your DNS cache has been properly cleared. Simply type "ipconfig /displaydns" into PowerShell after flushing your cache, and you should see an empty list indicating that your DNS cache has been cleared.

How to Flush DNS Cache in Linux?

Flushing nscd daemon cache

Flushing the DNS cache on Linux can be done through various methods. One such method is flushing the nscd daemon cache. The nscd (Name Service Caching Daemon) is a system service that caches and speeds up DNS lookups.

However, sometimes it may lead to outdated or incorrect cached information, resulting in issues while accessing certain websites. Therefore, it becomes crucial to flush the nscd cache at times.

To do this, first, open the terminal and enter the command "sudo systemctl restart nscd.service". This will restart the Name Service Caching Daemon and clear any cached entries for hostnames or IP addresses.

sudo systemctl restart nscd.service

Flushing systemd-resolved cache

Another method for flushing DNS cache on Linux is by using systemd-resolved. This is a service that provides name resolution to local applications through a D-Bus interface.

It also maintains a cache of resolved names and queries. To flush system-resolved's DNS cache, open up a terminal and type "sudo systemd-resolve --flush-caches".

sudo systemd-resolve --flush-caches

This will clear both positive (successful) as well as negative (unsuccessful) resolved entries from its cache. Once done successfully, you should see an output similar to "Flushing caches...".

You can verify if all caches have been cleared by running "sudo systemd-resolve --statistics" which displays statistics about the current state of system-resolved including cached entries count.

sudo systemd-resolve --statistics

By following these two methods mentioned above i.e., flushing the nscd daemon cache and flushing system-resolved cache, you will be able to successfully flush DNS caches on Linux and resolve any DNS related issues.

Troubleshooting Common Issues After Flushing DNS Cache

No Internet Connection after Flushing DNS Cache: Causes and Solutions

One of the most common issues users face after flushing their DNS cache is a loss of internet connection. This occurs because the system forgets the IP address for domain names that were previously visited and can't find them again. The first thing to do is check if there's an issue with your router or modem by resetting them.

If there's no issue on your network, you can try rebooting your device or clearing cookies and cache on your browser. If these solutions do not work, you may need to check if there's a problem with the DNS server settings in your system.

DNS Resolution Issues after Flushing DNS Cache

Another common issue users face after flushing their DNS cache is DNS resolution issues. This occurs when the system doesn't receive responses from its configured nameservers when trying to resolve domain names into IP addresses.

To fix this issue, first check if your network connection is stable and try pinging different websites from your terminal or command prompt to test connectivity. If connectivity tests fail, it's possible that there's an issue with the configuration of your nameservers' addresses in /etc/resolv.conf file (on Linux/macOS) or TCP/IP settings (on Windows).

Conclusion

Flushing DNS cache in macOS, Windows, and Linux is a simple process that can improve your device's networking performance by clearing out outdated or corrupted DNS cache entries. However, users may face troubleshooting issues after performing this process. By following the steps outlined in this article, you can quickly solve these issues and get back to browsing the internet smoothly.

Remember to always double-check your configurations and connections before assuming that there are issues with your system. Happy browsing!

Updated on: 05-Jun-2023

162 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements