jcanfield
1/15/2015 - 9:13 PM

Flush DNS Cache on Mac OSX 10.10 Script (includes DNS Cache flush for OSX 10.9, OSX 10.7-10.8, OSX 10.5-10.6, Windows and Linux)

Flush DNS Cache on Mac OSX 10.10 Script (includes DNS Cache flush for OSX 10.9, OSX 10.7-10.8, OSX 10.5-10.6, Windows and Linux)

#!/bin/bash
## Restart Networking and flush current DNS cache
## Old command are commented out
## Original commands came from http://coolestguidesontheplanet.com/clear-the-local-dns-cache-in-osx/
##
## NOTE: mv -v $THIS ~/.bin/osx-dnsflush.sh
## sudo ln -sb $THIS /usr/local/sbin/osx-dnsflush
## USAGE: osx-dnsflush

# Clear cache for Mac OSX 10.10
echo "Clearing DNS Cache..."
read -p "[Press Enter To Continue]"
sudo discoveryutil udnsflushcaches

# Mac OSX 10.9
# dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Mac OSX 10.7  – 10.8
# sudo killall -HUP mDNSResponder

# Mad OSX 10.5 – 10.6
# sudo dscacheutil -flushcache

# Windows cmd.exe
# ipconfig /flushdns

# Linux (common Debian variant)
# /etc/init.d/named restart
# /etc/init.d/nscd restart

echo "DNS Cache cleared..."

exit