This short article describes how to flush (or reset) the DNS cache. DNS queries (IP addresses) are usually cached, but sometimes it may be necessary to empty and flush the DNS cache. Clearing (or “flushing”) cache refreshes this data. For instance, if you experience a lot of 404 (cannot find server) error codes or you encounter issues where the named server is not resolving properly, you may want to reset your DNS cache. Luckily, this process is really easy.
About Your Mac’s DNS Cache
macOS and OS X keep a local cache of resolved DNS queries for a time specified by the DNS server. Sometimes it’s necessary to reset the cache immediately and re-query a DNS server. For example, if your DNS server has recently changed, you might need to do this.
If your Mac isn’t using the latest DNS entries from your server, restarting your Mac usually updates its cached information. If you want to update DNS entries and you can’t restart your Mac or Server using macOS or OS X, use the terminal commands below (dependent on macOS or OS X version.)
Flush the DNS cache in macOS Monterey and older Mac OS X versions
Starting with macOS El Capitan and newer, Apple changed how you can manually flush the DNS cache. The following method requires the use of Terminal, along with an all-new command. Despite the new command, the end result will remain the same as it has always been with previous versions of macOS. Here’s how you can flush the DNS cache in macOS El Capitan and newer:
- Open the Terminal app on your Mac.
- The easiest way is to press CMD+Space on your keyboard.
- Enter the following command:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
- Press Enter.
- If prompted, type your administrator password.
- Press Enter again to submit your password.
The DNS cache will automatically be flushed, but you won’t see any prompts with Terminal confirming that the process has been completed. Instead, after the DNS flush is finished, Terminal will move to a new line item, at which point the command will have been carried out. In the event that you type the password into Terminal but don’t see the cursor move, don’t be alarmed. This is just how Terminal operates, and as long as you enter the password correctly, the DNS cache will still be taken care of. If you enter a wrong password, Terminal will tell you as much, allowing you to re-enter the password or requiring you to enter the command again.
Open Terminal and enter the command below. This command clears MDNS and UDNS caches. DNS in macOS is handled through mDNSResponder, killing the process is the easiest way to reset your DNS cache on a Mac aside from rebooting and manually changing DNS settings.
sudo killall -HUP mDNSResponderThe command sudo dscacheutil -flushcache also works
OS X 10.10 Yosemite & El Capitan
Use the following Terminal command to reset the DNS cache in OS X v10.10.4 or later
sudo killall -HUP mDNSResponder
Use the following Terminal command to reset the DNS cache in OS X v10.10 through v10.10.3
sudo discoveryutil mdnsflushcache
Enter your admin password when prompted to perform the flush.
OS X 10.9 Mavericks
Open Terminal and enter:
dscacheutil -flushcache;sudo killall -HUP mDNSResponder
OS X Mountain Lion or Lion (10.7 and 10.8)
Launch the Terminal app (Applications > Utilities > Terminal) and enter (put in your admin password when prompted):
sudo killall -HUP mDNSResponder
Mac OS X 10.6 and 10.5
Open Terminal and type:
sudo dscacheutil -flushcache<c/ode>
Mac OSX 10.4 And Below
Launch Terminal and enter:
Verify Your DNS Issues Are Resolved
To check whether your DNS is now working normally, use the “dig” command. Stay in Terminal and type “dig appletoolbox.com.” Or the name of any website you regularly visit–just make sure you type dig before the web address.
The command dig is used for querying DNS name servers for information about host addresses, mail exchanges, nameservers, and related information. If speed is your issue, look under the ANSWER SECTION for the Query time.
If that number proves too high, meaning it’s taking too long for the site to load, change your computer’s, devices’, or router’s DNS settings to Open DNS Servers (188.8.131.52 & 184.108.40.206)or Google Public DNS Servers (220.127.116.11 and 18.104.22.168.)
Save a .scpt File to Your Desktop for Quick Access
- Open “Script Editor” and add the following command and then save to your desktop (copy and paste the following line including quotes)
- For macOS Sierra, do shell script “sudo killall -HUP mDNSResponder”
- For El Capitan, do shell script “sudo dscacheutil-flushcache; sudo killall -HUP mDNSResponder”
- Double-click that file anytime you need to flush the DNS
- If you want a message in Terminal letting you know that the DNS was flushed add the following command to your line
- ;say DNS cache was successfully flushed
Obsessed with tech since the early arrival of A/UX on Apple, Sudz (SK) is responsible for the original editorial direction of AppleToolBox. He is based out of Los Angeles, CA.
Sudz specializes in covering all things macOS, having reviewed dozens of OS X and macOS developments over the years.
In a former life, Sudz worked helping Fortune 100 companies with their technology and business transformation aspirations.