Refresh DNS after "etc/resolver" changes
If you’ve read some of my other blog posts, you know that I rely on a cool little feature of macos, the ability to specify custom nameservers matching some domain pattern. For example, if I want to use nameserver 10.1.1.10
whenever someone sends requests to subdomain *.harding.test
I could add this file:
File: /etc/resolver/harding.test
However, up until recently I found I had to restart my mac to get the OS to recoginize this new domain to nameserver mapping. There are guides out there that claim to offer solutions for clearing DNS cache without restarting, but none of them worked for my High Sierra Macbook Pro.
If I were to make the previous change and then run scutil --dns
you would not see the new nameserver included in the output.
But, to force a refresh of the OS DNS servers you can simply run something like this:
But with your preferred DNS servers included. I’ve also found that if the refresh is lazy, meaning if you already had this DNS server in your Wi-Fi Network Service you would need to try a different value, say:
Note the added 8.8.4.4
This same force refresh can be achieved by clicking on the System Preferences -> Network -> Advanced -> DNS gui, but that’s not as fun as a terminal command!