How to Flush DNS Cache in OS X El Capitan
If you adjust DNS settings on a Mac and the changes seemingly haven’t taken effect, or perhaps you discover that a given name server address is not resolving as intended, flushing the DNS cache is often a quick resolution. Flushing DNS cache in OS X El Capitan (10.11 or later) is easily possible with a trip to the command line, though if you’ve been using Mac OS X for a while you’ll notice the syntax is different, again, from some prior releases of Mac OS. This is because Apple has re-adopted mDNSResponder after temporarily ditching it for discoveryd, so the dscacheutil command will likely be familiar to some Mac users.
Flushing DNS Cache in OS X 10.11+
This method of clearing DNS cache applies to all Macs running versions of OS X El Capitan, versioned as 10.11 or later:
- Open the Terminal application, found in /Applications/Utilities/ or with Spotlight
- At the command prompt, enter the following syntax then hit return:
- Enter the admin password when requested (required by sudo) to execute the DNS cache clearing
- When you hear “DNS Cache flushed” you know the command has been successful*
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder; say DNS cache flushed
That’s it, the DNS cache will be flushed. You’ll likely want to quit and relaunch apps that are using DNS, like a web browser, for changes to carry over to apps connected to the internet.
Clearing local DNS caches is commonly required by web developers, network administrators, performing accurate detailed lookups with host, and anyone who edits the hosts file, or adjusts domain name settings for faster servers or for other purposes.
If you intend on flushing DNS caches often, a simple alias placed in your appropriate .profile can be beneficial for quick future usage:
alias flushdns='dscacheutil -flushcache;sudo killall -HUP mDNSResponder;say flushed'
Users can also cut out the say portion and split the command into several parts, though a one liner is often the easiest way to go.
sudo dscacheutil -flushcache
Then separately initiating the mDNSResponder killall command:
sudo killall -HUP mDNSResponder
Going this route will not provide any auditory feedback that the commands have been successful.
This applies to the latest versions of OS X, whereas those who are running earlier versions of Yosemite can find directions here for the same effect with a different command string, as can users of older Mac OS X releases like Mavericks and Snow Leopard, or even the dusty versions of Tiger, Panther, and Jaguar out there. On the mobile side of things, iPhone and iPad users can quickly flush DNS cache in iOS with a simple trick too.
I’m trying to get this to run in Automator but I keep getting
sudo: no tty present and no askpass program specified
I know its something to do with passwords. The weird thing is I think it works with the say command (It says the command). But if I take that out I get the error above. Anyone know how to fix this?
Thanks for the tip & the method works great!
Are you serious with that say command? Brogramming at it’s best.
It thought it was a cool feature, lol.
Replace with:
say -v cello droid
To do it the google way.
Better use this and hear a little classic tune:
say -v cello drooooooooooooooooooooooooooooooooooooooooooooooooid
would it be better to substitute ; with && in the commands? the semicolon just separates the commands, right? if so, having the `;` before the `say` command doesn’t really signify whether the commands truly executed. putting the `&&` would execute the `say` command if-and-only-if the previous commands executed properly?
Yes that is correct you can issue the command that way, if success && else ;
Flushes cache the same as long as the command is correct, you don’t need to have ‘say’ though
Odd. I had to type my Admin password six times before the response that cache was flushed was heard. So I enabled root for the first time through the System Preferences route. Throwing the lines to flush cache into Terminal a second time I was prompted to use the new root password, and the response came up. But now invoking the lines into Terminal a third time and then pressing Return immediately the response is heard. I don’t have to nor am I prompted for a password. Closing Terminal and a new window and again I add the lines to flush cache, press Return and now no prompt for a password, just the immediate response that cache has been flushed. Root appears to be on all the time now. I want to shut it off. Don’t know how as yet.
Odd.
If you have El Capitan you have a screwed up system. It runs extremely slow; doesn’t like Microsoft Office; disables wired keyboard and mouse from time to time. Has a hard time reloading after being shut down.
PCs and Macs are so similar that there is no advantage to spending the extra $ to buy a Mac when you can get a more powerful PC for under $500.
Flushing DNS cache will likely have no effect on Microsoft Office unless you have it connected to the Microsoft cloud as a save point and DNS changes. In that case, quit and relaunch MS Office and the DNS will work again.
What a strange comment, who cares if a PC is $500? This is about performing a flush of your DNS caches in OS X El Capitan. Want to talk about the weather too? 58° and cloudy, it could be better!
I want to talk about the weather! By “could be better”, do you mean your preference is for “beautiful weather”? And does that mean above-average temperatures and a monotonously blue sky with zero clouds?
I like a cloud or two. Even give me a rainstorm once in a while.
Yes true, I’m not at all impressed with my 10.11 Mac’s bluetooth performance neither, but that not what this article is all about.
PC’s and Mac’s are not similar. Considering I use both frequently I know that the Mac has many many more built in features that Windows does not have.
Here are some off the top of my head; Quick look, Time Machine, Dashboard, built in dictionary, built in text replacement, text to speech, multiple desktops, integrated features between applications and OS, built in advanced network tools,.
Windows 10 has some a FEW nice features I like over OSX but I don’t think they are the same at all.
You can build a fast car for cheap compared to a “luxury” car but that doesn’t make it better. Usually there are additional features that are included and the product is made out of better materials with better build quality.
I don’t know all those features on the Mac by hand, but multiple desktops have been available on the PC for quite a while. If we disregard other OS and focus on Windows 10 (which I assume you compare against since text to speech was a prominent feature of OS/2 4 back in the 90’s) virtual/multiple desktops are available. Text replacement was added by Mircosoft as long back as in DOS, so text replacement is built in since somewhere in the 80’s. Do I need to go on? Besides, this has nothing to do with the topic at hand.
The best of returning to mdnsresponder is the better networking stability. No idea why they left it to begin with.