21

I've read that sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache should flush the DNS cache on OSX (macOS Mojave).

However, this command kills processes without restarting them, and is both hard to remember and cumbersome. Also, AFAIK dscacheutil applies only to the directory service.

Doesn't OSX provide a command like Windows' ipconfig /flushdns to flush the system's DNS cache?

2 Answers 2

12

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.

1
  • Works like a charm. Thanks for the additional information, too. Commented Apr 8, 2020 at 19:53
6

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.

4
  • You can also add commands to restart the two services you killed. Commented Aug 3, 2019 at 22:35
  • 1
    It looks like the code above is combining what to do if you are running several different versions of MacOS. On osX 10.10.4 and above all you should have to do is sudo killall -HUP mDNSResponder See documentation.cpanel.net/display/CKB/… Commented Aug 3, 2019 at 23:20
  • @ThomasNelson. I got that command from help.dreamhost.com/hc/en-us/articles/… It said it was for Sierra or newer.
    – Natsfan
    Commented Aug 4, 2019 at 3:20
  • 2
    @jmh - but if I kill processes, don't I need to restart then again? Otherwise, I guess, I will have cleared the DNS cache, but won't have any DNS 😃
    – Shuzheng
    Commented Aug 4, 2019 at 4:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .