Last updated:

While programming on your Mac, you may find yourself in a situation where a DNS entry doesn’t return what you would expect because of a long DNS TTL (time-to-live) cache. This can occur when doing local development on Mac with various virtual machine or local server with internal DNS. In such cases, flushing your Mac OS DNS cache may be necessary to pick-up the updated entries without waiting for the TTL to expire. Unfortunately, there is not one consistent way to do it as it will depend on which Mac OS version you are running.

Below is a list of the command line that you can use to purge your DNS cache based of the Mac OS version that you are using. This is quite conveninent as you can add this to your build automation process for your local dev environment.

OS X 10.15 (Catalina)

[me@me-macOS: ~]$ sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

OS X 10.12 (Sierra), 10.13 (High Sierra), and 10.14 (Mojave)

[me@me-macOS: ~]$ sudo killall -HUP mDNSResponder

OS X 10.11 (El Capitan)

[me@me-macOS: ~]$ sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

OS X 10.10 (Yosemite)

Versions 10.10.4+:
[me@me-macOS: ~]$ sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Versions 10.10.1, 10.10.2, 10.10.3:
[me@me-macOS: ~]$ sudo discoveryutil mdnsflushcache; sudo discoveryutil udnsflushcache;

OS X 10.9 (Mavericks)

[me@me-macOS: ~]$ dscacheutil -flushcache; sudo killall -HUP mDNSResponder

OS X 10.7 (Lion) and 10.8 (Mountain Lion)

[me@me-macOS: ~]$ sudo killall -HUP mDNSResponder

OS X 10.5 (Leopard) and 10.6 (Snow Leopard)

[me@me-macOS: ~]$ sudo dscacheutil -flushcache

OS X 10.4 (Tiger) and before

[me@me-macOS: ~]$ lookupd -flushcache

👉 Bonus Tips #1: To find out which Mac OS version you are running, check the post How to Find which Mac OS version you are running?

👉 Bonus Tips #2: If you’d rather to use a point-and-click solution to purge your local DNS cache, check out the step-by-step guide from apple at https://support.apple.com/en-us/HT201260.

GET UNIQUE TIPS AND THE LATEST NEWS BY SUBSCRIBING TO MY NEWSLETTER.
AND FOLLOW ME ON