How to flush your DNS Cache on Mac OS X?

  • HOME
  • >
  • MAC
  • >
  • How to flush your DNS Cache on Mac OS X?
Last Updated: 

You may find yourself in a situation where a DNS entry doesn't return what you would expect because of a long TTL (time-to-live) cache. This can occur especially when doing local development with various virtual machine or local server with internal DNS. In such cases, flushing your Mac OS DNS cache may be necessary in order 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 specifically on which Mac OS version you are running.

👉 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.

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

Related mac posts that you may like
How To Use Option as Meta Key in macOS Terminal?
The Meta Key is a modifier key that can be quite helpful to improve your productivity while working in a terminal and bash. This post cover how to enable from the command line the Meta Key in macOS Terminal.
How To Change Preferences from the Command Line on macOS?
Learn how to optimize your workflow on macOS by automating all your Finder and Applications preferences. This post introduce the use of the macOS command line 'defaults' and provide examples on how to programmatically change user preferences.
How To Upgrade your Bash Version on macOS?
MacOS comes with an outdated version 3 of Bash which is quite frustrating when trying to script more advanced solution and get compatibility across various systems. This post will show you how to easily upgrade your Bash version on MacOS from the command line.