Skip to content

Instantly share code, notes, and snippets.

@thewellington
Last active April 22, 2026 16:56
Show Gist options
  • Select an option

  • Save thewellington/6736175 to your computer and use it in GitHub Desktop.

Select an option

Save thewellington/6736175 to your computer and use it in GitHub Desktop.
Flush DNS in OS X
#!/bin/bash
#
# flushdns
# This script will flush your DNS cache on Mac OS X 10.1 - 26.x
# The method for doing this chages it seems in every version of OS X,
# and I can never remember the correct command, so I wrote this script
# and gave it a name I could remeber.
#
# v.2026-04-22 by bill@wellingtonnet.net
# https://gist.github.com/thewellington/6736175
OSX_VERSION=`sw_vers -productVersion`
echo "Attempting to flush DNS cache"
case $OSX_VERSION in
# OS X 10.1 - 10.4 (Puma, Jaguar, Panther, and Tiger )
10\.[1-4]*)
echo "Flushing DNS cache for 10.1-10.4"
lookupd -flushcache
;;
# OS X 10.5 & 10.6 (Leopard and Snow Leopard)
10\.[56]*)
echo "Flushing DNS cache for OS X 10.5 - 10.6.*"
dscacheutil -flushcache
;;
# OS X 10.7 & 10.8 (Lion and Mountain Lion)
10\.[78]*)
echo "Flushing DNS cache for OS X 10.7 - 10.8.*"
killall -HUP mDNSResponder
;;
# OS X 10.9 (Mavericks)
10\.9*)
echo "Flushing DNS cache for OS X 10.9.*"
dscacheutil -flushcache
sudo killall -HUP mDNSResponder
;;
# OS X 10.10 - 10.10.3 - the crappy times (Yosemite, part 1 )
10\.10|10\.10\.[1-3])
echo "Flushing DNS cache for OS X 10.10 - 10.10.3"
sudo discoveryutil mdnsflushcache
sudo discoveryutil udnsflushcache
;;
# OS X 10.10.4 and up -- long live mDNSResponder! (Yosemite, part 2 )
10\.10\.[4-5])
echo "Flushing DNS cache for OS X 10.10.4+"
dscacheutil -flushcache
sudo killall -HUP mDNSResponder
;;
# OS X 10.11 - 10.12.2 -- El Capitan, and Sierra
10\.11|10\.12|10\.12.[1-2]*)
echo "Flushing DNS cache for OS X 10.11 - 10.12.2"
dscacheutil -flushcache
sudo killall -HUP mDNSResponder
;;
# macOS 10.12.3 - 10.15 -- Sierra, High Sierra, Mojave, and Catalina
10\.12.[3-6]*|10\.1[3-5]*)
echo "Flushing DNS cache for macOS 10.12.3 - 10.15.*"
sudo killall -HUP mDNSResponder
sudo killall mDNSResponderHelper
dscacheutil -flushcache
;;
# macOS 11.0 -- Big Sur and Monterey, when in compatibility mode show up as "10.16". (SYSTEM_VERSION_COMPAT=1)
10\.16*)
echo "Flushing DNS cache for macOS 10.16 (11 & 12 in compatibility mode)"
sudo killall -TERM mDNSResponderHelper
sudo killall -TERM mDNSResponder
dscacheutil -flushcache
;;
# macOS 11.0 12.x -- Big Sur, Monterey, Ventura, Sonoma, and Sequoia
11\.*|12\.*|13\.*|14\.*|15\.*)
echo "Flushing DNS cache for macOS 11-15.*"
sudo killall -TERM mDNSResponderHelper
sudo killall -TERM mDNSResponder
dscacheutil -flushcache
;;
# macOS 26.x -- Tahoe
26\.*)
echo "Flushing DNS cache for macOS 26.*"
sudo killall -TERM mDNSResponderHelper
sudo killall -TERM mDNSResponder
dscacheutil -flushcache
;;
# Catch anything else...
*)
echo "Sorry, this script is not prepared to handle your version of OS X / macOS."
exit 1
esac
echo "DNS cache flushed."
exit 0
@thewellington

thewellington commented Apr 22, 2026

Copy link
Copy Markdown
Author

Updated through macOS Tahoe

it has been a while, but here is my favorite script updated all the way through Tahoe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment