How to reset the DNS cache in OS X

When troubleshooting network and Web connectivity, in addition to tackling browser caches and configurations, you might also consider refreshing your DNS cache.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
3 min read

The Domain Name System (DNS) is a hierarchical network that resolves text-based URLs such as "www.cnet.com" to the servers' IP addresses that your computer uses for communication. While loading a single Web page or other Web-based resource, your computer may contact numerous URLs to load different components (a Web page, images on it, an application hosted on it, scripts, etc.), so a robust DNS service is a vital part of having a smooth Internet connection.

Even though a fast DNS service will optimize a connection, redundant queries to it will take time to complete. Therefore, based on your DNS server's configuration OS X will cache its DNS query results for a predetermined amount of time to allow quicker access to the results of recent DNS lookups. This time is usually relatively short -- between a few minutes to a few hours -- but this time depends on the DNS server being used; some may be configured to update the cache at far greater intervals such as a day or longer.

While for the most part the cache should optimize connections and keep your Internet connections running smoothly, there are times when it becomes corrupted or contains out-of-date information and doesn't properly resolve a needed Web resource. Problems with the cache can also lead to a slower browsing experience.

Therefore, if you are experiencing browsing problems, then along with other routines like clearing your browser's cache and troubleshooting network connections, your router settings, and browser plug-ins, you might also consider clearing the cache. Apple has recently outlined how to do this in a small knowledge base article, since the methods for doing this have changed in recent releases of OS X.

The classic method of clearing the DNS cache is to run the following command in the Terminal:

sudo dscacheutil -flushcache

However, in OS X Lion and Mountain Lion, Apple has changed the method for caching DNS queries, which unlinks it from the "dscacheutil" command, so if you run this in newer versions of OS X, you may get an error that states, "Unable to get details from the cache node." In these versions of OS X, Apple has changed the caching routines done by the mDNSResponder process (the core process responsible for DNS resolution) so they are kept in memory by the process as long as it maintains a connection to the DNS network. Therefore, to clear the cache, you just need to send the mDNSResponder process a hang-up command to have it reinitialize its configuration without being fully shut down and restarted. To do this, you can run the following command in the Terminal:

sudo killall -HUP mDNSResponder

Activity Monitor sending the SIGHUP signal
You can send the SIGHUP signal to the mDNSResponder process in Activity Monitor as well as via the Terminal. Screenshot by Topher Kessler/CNET

In addition to the killall command in the Terminal, you can also do this in Activity Monitor by the following process:

  1. Open Activity Monitor (in the /Applications/Utilities/ folder).
  2. In the main Activity Monitor window is not present, press Command-1 to show it.
  3. Locate and select the mDNSResponder process (you can search for it to make this easier).
  4. Choose Send Signal To Process from the View menu.
  5. Select Hangup from the menu that appears (it should be the first option that is already selected).
  6. Click the Send button.

When you do this, you may see another mDNSResponder process appear for a few seconds in Activity Monitor as the system reinitializes the process, and once this disappears, the DNS cache should be cleared.

Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.