Flush the DNS Cache on Mac OS El Capitan (using a nice quick alias)

Updated June 2016: For OS X / 10.11 / El Capitan

Problem: I’ve updated some Name Server records on a domain and I want to check they’ve propagated using Dig. When I dig mydomain.com ns I keep getting the old results.

Solution: The local DNS cache on the machine needs to be cleared. As far as the OS is concerned, it’s already looked up that domain name and doesn’t need to do a fresh lookup until the domain record’s TTL (time to live) has expired.

On OS X 10.11 El Capitan there are two things needed. Firstly clearing the Directory Service cache and secondly forcing mDNSResponder to restart. This can be done using two commands in Terminal¹:

$ dscacheutil -flushcache
$ sudo killall -HUP mDNSResponder

A Nice Quick Alias: But really… who’s going to remember that? So I’ve added an alias to make it easier. Aliases are added (amongst other places) to your user’s .bash_profile² file. To edit your bash profile file, open it with the following command in terminal¹:

$ nano ~/.bash_profile

Then once nano (the text editor) is open, add the following line to the file:

alias flushdns='dscacheutil -flushcache;sudo killall -HUP mDNSResponder;say -v Zarvox dee enn es flushed'

To save the file, press Control (ctrl) + x and follow the prompts.
Once this is saved, load the changes you’ve made into your current terminal session with the command:

$ source ~/.bash_profile

Now when you type flushdns in terminal, your caches will be cleared! woo!

Tips:
1. The quickest way to open Terminal (or anything actually) is to use Spotlight. Press the Command (cmd) + Space keys, and type ‘Terminal’ in the resulting input, then press Return / Enter.
2. If your bash profile doesn’t exist, it might be empty when you type the nano command above. This is ok, when you Control (ctrl) + x after adding the line, the new file will be created.
3. When opening the bash profile file, I used ~/ before the file name. This is to ensure that it opens the profile file of the user you’re currently logged in as.
4. You might notice the ‘say’ command in the alias. This uses the built-in Mac OS text-to-voice engine to say “DNS flushed” in a robotic voice… just getting y’all used to it for the robot uprising 🙂

Please let me know if this post was useful with a click!
Nope, not helpful...Yep, more useful than not! (No Ratings Yet)
Loading...

1 thought on “Flush the DNS Cache on Mac OS El Capitan (using a nice quick alias)”

Leave a Reply

Your email address will not be published. Required fields are marked *