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.
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
In addition to the killall command in the Terminal, you can also do this in Activity Monitor by the following process:
- Open Activity Monitor (in the /Applications/Utilities/ folder).
- In the main Activity Monitor window is not present, press Command-1 to show it.
- Locate and select the mDNSResponder process (you can search for it to make this easier).
- Choose Send Signal To Process from the View menu.
- Select Hangup from the menu that appears (it should be the first option that is already selected).
- 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.