You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

What's the best way to clear the DNS Cache in High Sierra

What's the best way to clear the DNS Cache in High Sierra? I've seen conflicting answers and I wish to have the best current way for a bash script.

Posted on Aug 22, 2019 12:31 PM

Reply
13 replies

Aug 22, 2019 12:38 PM in response to BobTheFisherman

Say I am using an API in a script to update a DNS A or CNAME record, and I want to clear my local cache, during script runtime to then test that my change worked. Assume I know what I'm doing and will go to the source to avoid any recursive caching issues.


Rebooting get's me the outcome, but I want to know if:

sudo killall -HUP mDNSResponder


is the best way or if there is a way to do it without killing a process or maybe even avoiding sudo.


For example, in windows you can do:

ipconfig /flushdnscache


Aug 22, 2019 4:55 PM in response to BDAqua

BDAqua wrote:

I can't be positive but it seems adding/changing DNS servers in Network Pref Pane resets it.


That’s a little more difficult to script, though...


There is a command-line interface into that area of macOS, using the networksetup command. (That probably will flush the DNS cache, but that’ll be a fairly obscure usage, and I’d rather not toggle the DNS servers regardless.)


I’d still HUP the responder. That HUP-age makes it explicitly clear what you’re up to, here.

Aug 23, 2019 7:26 AM in response to MrHoffman

I appreciate everyone's responses. I want to emphasize that my question was "what is the best way", not "tell me what to do". I was trying (maybe to an academic fault) to find out if there was a specific command that accomplished my need. the kill command is a workaround, in my opinion.


I don't think it's unreasonable to wish to have a strategy to accomplish a task that is not essentially - kill it and hope for the best.


I understand that while that gets me the desired outcome, it's doesn't exactly give me the warm fuzzies. I'd prefer an explicit command that is designed to achieve my desired outcome (flush dns cache). It would be even better if I could just flush a domain from the cache.


Unfortunately - I don't think there is a command that achieves this explicit outcome by design. I will continue to use the kill command to accomplish this.


Thanks for the networksetup command, I was unaware of that - although it doesn't provide me what I'm looking for. The strange situation as a developer I run into a lot is that I don't usually need to do the server type things that say - the network setup command enables because I'm not in the business of provisioning macs.


I am in the business of testing outcomes, and while the kill command will work for testing from my laptop, I will likely end up running the script from a linux box.


Thanks everyone.

Aug 23, 2019 2:32 PM in response to punkrokk

For "Turing complete", the memory management unit (MMU) on x86 is. In isolation.


So too is the x86 mov instruction. Again, in isolation. Without the rest of the x86 processor.


And whatever you pick here, Apple—and as has happened before—may well change the commands needed.


Pick what is common and works, document the intent, and...


"Best way", "best practices", "top 10", and such are all subjective.


What's the best way to clear the DNS Cache in High Sierra

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.