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.
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.
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
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.
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
punkrokk wrote:
ok - So is this the best way?
Seems the there has to be a way to clear the cache without killing a process. Maybe I'm just too hopeful.
Just kill the process, and get on with whatever you're hacking around with this script.
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.
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.
You asked for the "best way" and so that is what I provided. The "best way" for me may not be the "best way" for others. This is why "best way", best app", best computer", best display", are not very productive questions.
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.
yes
sudo killall -HUP mDNSResponder
is a valid terminal command, Clear DNS Cache, say dns cleared successfully
Also the kill all approach just exits 0, and doesn't provide any useful feedback.
What are you trying to achieve?
Reboot your computer.
ok - So is this the best way?
Seems the there has to be a way to clear the cache without killing a process. Maybe I'm just too hopeful.
I can't be positive but it seems adding/changing DNS servers in Network Pref Pane resets it.
I think they'd be better off using your suggestion also.
Fair enough. I assumed folks would interpret as the best "turing complete" way. haha. My bad :)
What's the best way to clear the DNS Cache in High Sierra