How to flush your DNS Cache on Mac OS X?

  • HOME
  • >
  • MAC
  • >
  • How to flush your DNS Cache on Mac OS X?
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.

Related mac posts that you may like...
How To Format Date and Time in Linux, macOS, and Bash?
This guide covers how to format date and time in Linux, Mac, and the Bash shell. Includes how to do date shell operations like adding days or comparing dates.
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?
Introduction to the command line 'defaults' on Mac with examples on how to programmatically change user preferences from a shell script and terminal.
How To Upgrade your Bash Version on Mac OS?
MacOS comes with an outdated version Bash which can be limiting in shell scripts. This post explain how to upgrade your Bash version on Mac from the command line.