AppleInsider may earn an affiliate commission on purchases made through links on our site.
Although very rarely needed, clearing the DNS cache can help resolve mysterious internet connection issues. Here’s why, when and how you do it.
This is one of those tips you may never need to employ. That said, it’s a useful trick to have as part of a Mac user’s troubleshooting arsenal when a Mac has problems connecting to websites, and the usual series of easy fixes – also known as the name of “restart everything” – does not solve this.
This particular trick isn’t that easy if you’re not familiar with the Terminal app, but don’t worry, we’ll walk you through it.
Your Mac, router, and ISP all have DNS caches running to keep you connected to your most-visited websites ever faster, so let’s start there.
What is a DNS cache used for?
You may already know that every website or other location on the internet actually has a numeric address rather than the name you think: for example, you would type “apple.com” into a browser, but the actual IPv4 address is 220.127.116.11. Humans aren’t particularly good at remembering strings of numbers versus words, so the Domain Name System (DNS) was created, turning those addresses into easily remembered names.
Each ISP uses a cache of addresses of frequently visited sites to create a faster connection to the right place on their own DNS servers, and uses it to perform a faster search for the real address of any website, once it receives the request from your computer. . For the same reasons, most routers also keep a small cache of frequently visited site addresses, just like your computer.
If your Mac can retrieve any site’s IP address faster than waiting for the ISP’s DNS server, it will take you there directly – bypassing any possible delays in finding other DNS servers along your ” itinerary” of the request to the service of the site.
This whole process only takes a few tenths of a second on a fast connection, but you may still be able to detect that if you return to a website you recently visited, the page still seems to load faster than if you visit a website you’ve never been to before.
This is because if the “lookup” – the conversion of name to IP numbers – for unvisited is not already cached on your computer, the browser goes back to the ISP’s DNS server to find the real address, which takes a bit longer — maybe a few seconds longer if you’re one of the few to visit that website.
Internet connection issues
Connection problems can occur when the ISP’s DNS server has its own problems – which would affect all devices connected to Wi-Fi in your household – or when your router’s DNS cache is corrupted, or if the DNS cache on your own computer has problems. This can be caused by simple cache write errors, or in very rare cases by malware.
If you are having difficulty accessing websites on any of your devices using your Wi-Fi connection, the first thing to try is the simplest thing – restart the router, restart the affected devices and see if the connection problem goes away. Alternatively, you can:
- Disable private relay, if enabled
- Go to System Preferences -> Network -> Advanced
- Click on the DNS item in the tabs. Write down what the numbers are first, just in case something goes wrong.
- Add Cloudflare’s 18.104.22.168 and 22.214.171.124 DNS servers instead
- Click OK
If going to websites suddenly works after this, the problem was with your ISP’s DNS server and will likely be resolved within a few hours. You can restore the ISP servers later by simply deleting the 126.96.36.199 address later and restarting.
If that hasn’t worked – and especially if you find that you can’t access your frequently visited sites but random never-visited sites actually get through – flushing your machine’s DNS cache could be the solution.
Apple doesn’t provide a graphical or easy way to “flush” a DNS cache due to the scarcity of your needs and the risk of accidental damage to things if the steps below aren’t followed carefully – as with anything involving Terminal. The procedure isn’t complicated and using a copy/paste for the command will help ensure no mistakes are made, but if after reading ahead you don’t think it’s That’s something you want to do — or if you’re using an older, unsupported version of macOS before El Captain, it might be best to contact a local expert to help you out.
- Quit, don’t just minimize your open apps.
- You should then see a “Go” menu in the menu bar at the top of the screen. The last option in the Go menu will be the Utilities folder. Select that.
- A window will open with the contents of this folder. One of them is called “Terminal”.
- Double click on it to open it
- You should now see a plain text window, ending with your short username and a cursor.
- Since commands in the Terminal must be typed using exact syntax, it is better to copy and paste the following command rather than trying to type it yourself:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
- Once this is pasted, press Enter/Return
- You will be prompted for your Mac’s login password. Although you type it, the terminal doesn’t show it at all – so go slow and make sure you spell the password correctly.
- Then press Return or Enter again.
If you don’t receive another password prompt or error message, you will have run the command successfully. Close the terminal window and try using your favorite browser to visit a website.
It might load a little slower than before, but if it loads fine, flushing the DNS cache fixes the problem and your Mac’s DNS cache will rebuild over time. Pat yourself on the back.