Skip to content

Instantly share code, notes, and snippets.

@matthieuprat
Last active August 29, 2015 14:09
Show Gist options
  • Save matthieuprat/1f17d877a175ace9145d to your computer and use it in GitHub Desktop.
Save matthieuprat/1f17d877a175ace9145d to your computer and use it in GitHub Desktop.
Flush DNS cache on Mac OS X
#! /bin/sh
# Flushes the DNS cache on Mac OS X
#
# From https://www.madboa.com/blog/2014/10/24/mac-dns-cache/
#
# Only tested on Yosemite.
MAC_OS_X_VERSION=$(sw_vers -productVersion | awk -F '.' '{print $1 "." $2}')
case "$MAC_OS_X_VERSION" in
10.1[0-9]) # Yosemite and above (fingers crossed).
sudo discoveryutil udnsflushcaches
;;
10.[7-9]) # Lion, Mountain Lion, Mavericks.
sudo killall -HUP mDNSResponder
;;
10.[5-6]) # Leopard, Snow Leopard.
sudo dscacheutil -flushcache
;;
10.[1-4]) # Tiger and earlier (tribute to the early beginnings of OSX).
sudo lookupd -flushcache
;;
*)
echo "$0: error: Unknown Mac OS version: $MAC_OS_X_VERSION"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment