How to flush the DNS cache on macOS?

Solution 1:

mDNSResponder is started by launchd whenever a DNS query is performed in the system. So it will restart the next time some process performs a DNS query.

Killing this process is not required though, sending the HUP signal with

sudo killall -HUP mDNSResponder

already flushes the cache. This hasn't change up to 10.15.

dscacheutil is only for 10.6 and you need a different command from 10.10.0 to 10.10.3, that's because Apple wanted to replace mDNSResponder with 10.10, yet the replacement had so many problems that they reverted back in 10.10.4 and stayed with mDNSResponder ever since.

Solution 2:

I don't know of a shortcut but you could easily put the one-liner

sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache

in a text file, name it DNSflush.sh for example, and use that as your command. Make the file executable and then run it from the terminal. I just did this and named the file simply DNSFlush and it worked fine.

The sudo command required me to enter my password.