How to manually clear the DNS cache on a Mac computer running macOS Sierra or later?
Managing Domain Name System (DNS) settings is a useful approach when encountering connection issues. Commonly, DNS settings are managed by network/system administrators or web developers. DNS settings are responsible for translating domain names to Internet Protocol (IP) addresses. Without DNS servers, Internet users would have to remember the IP address of each website. For example, rather than typing www.apple.com in the Internet browser, users would have to type 188.8.131.52 - obviously, not very convenient. There are situations when you will need to clear DNS cache, such as to ensure that the name server responds correctly. Also, if you have made changes in the /etc/ hosts file, you must clear the DNS cache for them to take effect. This last point is not often mentioned in many guides - changes might not take effect until DNS cache is reset.
Restarting the Mac will often clear DNS cache, however there are cases when a reboot is not an option. Clearing DNS cache settings is not a difficult task, but since it includes using the command line, it may seem confusing as first, especially if you are not familiar with using Terminal commands. Note that these commands, and the procedures, vary with each version of the Mac operating system - this guide explains how to reset DNS cache on the macOS Sierra operating system.
Table of Contents:
- How to clear DNS cache on computers running on MacOS Sierra or later
- Alternative method to reset DNS cache on Mac computers
- Video Showing how to reset DNS cache on Mac computers running on MacOS Sierra or later
How to clear DNS cache on computers running on MacOS Sierra or later
To begin the process, launch the Terminal application by using Spotlight. Press Command and Spacebar, or through finder, go to Applications and then Utilities. Next, type the following command (if possible, copy-and-paste or type it carefully, since upper/lower case and space errors will invalidate the command): sudo killall -HUP mDNSResponder;say DNS cache has been flushed
Press the return key and, since you are using the sudo (super user) permissions, enter your administrator account password to confirm the action. Wait a few moments until you hear an audio alert announcing that the DNS cache has been flushed when process completes. This will apply the changes made to DNS settings or /etc/ host files.
Alternative method to reset DNS cache on Mac computers
In some cases, you might need to quit and relaunch any active applications that are using the DNS or network such as Safari, Chrome, Firefox, Opera, sFTP, SSH and any similar tasks relying on domain name correspondence. This particular command can fail, but this is not a significant issue, since there is an alternative command available in newer versions (Sierra 10.12.3 and above) of macOS. Type the following:
sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache;say MacOS DNS cache has been cleared
Press the return key to execute, and confirm the action with the administrator's password.
Note: this step is based on modern version of macOS such as Sierra 10.12 and later. The methods on earlier versions vary slightly.
Video Showing how to reset DNS cache on a Mac computer running MacOS Sierra or later: