Last active
January 13, 2016 16:22
-
-
Save josheinstein/40f165450cafe631be2c to your computer and use it in GitHub Desktop.
Flushes the DNS cache in all recent versions of OSX. I'm not a Bash guy so this is probably sloppy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from the following post: | |
# How to Flush DNS Cache in Mac OS X | |
# http://osxdaily.com/2008/03/21/how-to-flush-your-dns-cache-in-mac-os-x/ | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root." 1>&2 | |
exit 1 | |
fi | |
OSVERSION=$(sw_vers -productVersion) | |
case "$OSVERSION" in | |
10.11.*|10.9.*) | |
echo "On $OSVERSION (dscacheutil -flushcache + killall -HUP mDNSResponder)" | |
dscacheutil -flushcache | |
killall -HUP mDNSResponder | |
;; | |
10.10.*) | |
echo "On $OSVERSION (discoveryutil mdnsflushcache + udnsflushcaches)" | |
discoveryutil mdnsflushcache | |
discoveryutil udnsflushcaches | |
;; | |
10.7.*|10.8.*) | |
echo "On $OSVERSION (killall -HUP mDNSResponder)" | |
killall -HUP mDNSResponder | |
;; | |
10.5.*|10.6.*) | |
echo "On $OSVERSION (dscacheutil -flushcache)" | |
dscacheutil -flushcache | |
;; | |
10.4.*|10.3.*) | |
echo "On $OSVERSION (lookupd -flushcache)" | |
lookupd -flushcache | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment