Apple

How to flush DNS cache in OS X Yosemite

Occasionally, you may run into problems that require you clearing the DNS cache on your Mac. Here's how to properly flush the DNS cache in the latest version of Apple's operating system.

terminal.jpg
Image: Apple

In today's connected workplace, webpage errors are a major headache for IT administrators. A good place to begin your troubleshooting is with the DNS cache.

For the uninitiated, DNS refers to Domain Name System, which acts as a directory of sorts for internet-connected devices. Your local DNS cache stores IP addresses of the web servers behind recently-viewed pages.

If you are experiencing problems with specific sites, or running into error codes such as the infamous HTML404 error code, it might be time to clear, or flush, your DNS cache. This will force your machine to query the servers in question for the current information.

For Mac users, the steps to clearing the DNS cache have changed with almost every succession of the operating system. I'm going to walk you through flushing the DNS cache in Apple OS X Yosemite.

Begin by opening the "Terminal" application on your Mac. Terminal is Apple's line command system for the OS. You can locate Terminal by opening a Finder window and clicking "Applications." Once in Applications, click on a folder labeled "Utilities," and then double-click on "Terminal."

terminalapps.jpg
Image: Conner Forrest/TechRepublic

Or, you can use the spotlight shortcut by holding the Command key and hitting the spacebar to open a search bar in the top right of you screen. Then, simply type "terminal" in the search bar and click on the application in the search results.

terminalsl.jpg
Image: Conner Forrest/TechRepublic

It's important to note here that Terminal will allow you to clear both the Multicast DNS (MDNS) and Unicast DNS (UDNS) using separate commands. This is helpful if you are trying to troubleshoot down to a more granular level. But, if you just want to fix the problem, they can both be flushed at the same time.

Let's start with clearing them separately.

Once you have the Terminal window open, type the following command and hit enter/return to flush the MDNS. If prompted, type in your password for your user account on your Mac.

sudo discoveryutil mdnsflushcache

To clear the UDNS cache, again in the Terminal window, type the following command and hit enter/return.

sudo discoveryutil udnsflushcaches

Or, if you want to save some time and clear everything out at once, you can string the two commands together in Terminal. You can type them in either order, as long as you separate the commands with a semi-colon. So, it should look something like this:

sudo discoveryutil mdnsflushcache;sudo discoveryutil udnsflushcaches

If you are unfamiliar with Terminal, be aware that it will not alert you when it finishes clearing the cache. It will simply open up another command line below the one you just ran. However, it will let you know if it doesn't understand the command or if there's an error.

For those who just want to check in on their DNS cache, you can type the following command to get statistics on your MDNS cache.

sudo discoveryutil mdnscachestats

If you want statistics on your UDNS cache, use this command instead.

sudo discoveryutil udnscachestats

If you run one of the statistics commands, you should see a report pop up in your terminal window under the command line that looks something like this.

mdnsstats.jpg
Image: Conner Forrest/TechRepublic

Note that I ran the stats after I flushed the cache. If you run it before, there probably will be few, if any, zeroes in the report.

Hopefully these tips will resolve some of your browsing issues and get you back to work quickly.

Also see

About Conner Forrest

Conner Forrest is a Senior Editor for TechRepublic. He covers enterprise technology and is interested in the convergence of tech and culture.

Editor's Picks

Free Newsletters, In your Inbox