If you ever updated a website or changed DNS records for a domain or web hosting account, there is a good chance that you ran into an issue where the website wasn’t updated or loading properly. The reason for this is often because the new DNS records weren’t propagated yet or, more specifically, the domain wasn’t updated on your local machine.
The Domain Name System (DNS) is a database that stores the relationship between domain names and their IP addresses. To make browsing the web faster, your machine caches DNS records so that it doesn’t have to query the DNS server every time it needs to resolve a domain name. However, it’s not unusual that the DNS cache on your local machine contains incorrect information, especially when changes were made to a domain recently. Flushing DNS is a process of clearing your computer’s DNS cache so that it fetches the latest DNS information from the DNS server.
In this guide, you’ll learn what DNS cache is, why you should clear it, and how to clear the DNS cache in Windows, macOS, and Linux.
What is DNS Cache?
DNS cache is a database that your computer maintains and stores recently resolved domain names with their matching IP addresses.
When you first visit a website, your computer contacts a DNS server to retrieve the IP address for the domain you type in the address bar. To avoid querying the DNS server for the same domain names each time you want to visit a website, your computer caches the results of previous queries.
This helps websites load faster because it reduces the number of queries needed to get a domain’s IP address.
Why Should You Clear DNS Cache?
Even though DNS caching speeds up browsing, the information in the DNS cache can become out-of-date over time
You need to clear DNS cache when:
• A website is moved to a new server
• DNS records are changed
• Website hosting provider is changed
• SSL certificate is renewed or reinstalled
• You visit a website that displays an old version
• You get DNS related errors
• You cannot access a website that you know is online
• A website is malfunctioning
• You want to troubleshoot connection issues
Clearing the DNS cache will refresh the entries and ensure that the latest data is available.
How to Clear the DNS Cache in Windows?
The quickest way to clear DNS cache in Windows OS is to use the command prompt.
This will clear the resolver cache in just a few seconds.
Step 1: Open Command Prompt
Click the Start menu, search for Command Prompt, and select Run as administrator.
Step 2: Run the Flush Command
Enter the following command:
ipconfig /flushdns
Step 3: Verify the Result
If successful, Windows displays the following message:
Successfully flushed the DNS Resolver Cache.
Your computer will now request updated DNS records whenever you visit a website.
How to Clear DNS Cache on macOS
The command varies slightly depending on the macOS version, but modern releases use a similar process.
Step 1: Open Terminal
Navigate to:
Applications → Utilities → Terminal
Step 2: Run the Flush Command
For recent macOS versions, use:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Step 3: Enter Your Password
Type your administrator password when prompted.
Unlike Windows, macOS usually doesn’t display a confirmation message. If no errors appear, the cache has been cleared successfully.
How to Clear DNS Cache on Linux
Linux distributions use different DNS services, so the command depends on the system you’re using.
Using systemd-resolved
Many modern distributions such as Ubuntu use systemd-resolved.
Run:
sudo resolvectl flush-caches
Alternatively, on some systems:
sudo systemd-resolve –flush-caches
Using nscd
If your system uses the Name Service Cache Daemon, restart it with:
sudo systemctl restart nscd
Using dnsmasq
For systems running dnsmasq:
sudo systemctl restart dnsmasq
After restarting the DNS service, your system begins using fresh DNS records.
How to Check Whether the DNS Cache Was Cleared
After clearing the DNS cache, try to check if the previously broken resource started working.
You can do it in several ways:
- Reload the page or restart the browser.
- Use another browser.
- Test the IP address with nslookup.
- Check propagation with DNS lookup tools.
If everything started working, it means that the cache was indeed the issue.
When Should You Flush DNS Cache
In most cases, there is no need to clear the DNS cache. However, it may be helpful in the following situations.
After changing DNS records
If you made any changes to A records, CNAME, MX, or DNS servers, you may want to clear the cache to ensure that your computer uses the updated data.
After website migration
If you moved your website to a new host, it may take some time for the propagated DNS records to resolve to the new IP address.
While troubleshooting a website
If your site is working for everyone except you, it may be helpful to clear the DNS cache to see if it resolves the issue.
After getting rid of malware
Malware may modify the host file or DNS settings, so it’s important to clear the cache after cleaning the system.
Does Clearing DNS Cache Make Internet Faster
In most cases, it won’t. Actually, it may slow down your computer after clearing because you have to wait for the new requests to be resolved.
However, it may improve the performance if you are trying to reach a site with an incorrect IP address because of a DNS error.
Browser DNS Cache vs Operating System DNS Cache
Modern browsers often have their own DNS resolver and cache. If clearing the OS cache didn’t help, try restarting the browser after emptying the browsing data.
Some browsers (e.g., Chrome) allow you to clear the internal DNS cache as well.
You can also try checking the website in the incognito mode to see if it helps.
Avoiding DNS Issues in The Future
There is no ultimate way to prevent DNS-related problems from occurring, but you can reduce the chances by following these recommendations:
- Use trusted DNS providers
- Keep the operating system up to date
- Wait before making any DNS-related changes
- Double-check everything before updating DNS records or migrating a website.
- Restart the router after making any significant DNS-related changes.
- Clear browser cache when testing website-related issues.
Conclusion
The DNS cache plays an important role in speeding up the domain resolution process, but it may also cause issues when the cached data is incorrect. Now you know how to clear the DNS cache on Windows, Mac, and Linux. You also understand why it’s important to clear it from time to time. After flushing the DNS resolver cache, you should be able to get rid of most of the DNS-related issues without affecting your servers. If you manage multiple sites and servers, consider using a web hosting control panel because it typically has built-in DNS management tools. It also allows you to make other website-related changes without having to log in directly to the server.