I wanted to use non-default DNS resolver for one specific domain, and the first idea was to simply use local dnsmasq. While looking for MacOS version, I found out that I can achieve the same simply by creating a file with domain name in /etc/resolver/example.com, with simple one line:
nameserver 8.8.8.8
All was good and works as expected, the resolution works, and scutil --dns confirms:
resolver #8
domain : example.com
nameserver[0] : 8.8.8.8
flags : Request A records
reach : Reachable
The next thing, I wanted to share this with a friend, by creating a simple one liner that he could run in his terminal:
sudo mkdir -p /etc/resolver/ && echo "nameserver 8.8.8.9" | sudo tee /etc/resolver/example.net
Again, scutil --dns confirms:
resolver #10
domain : example.net
nameserver[0] : 8.8.8.9
flags : Request A records
reach : Reachable
Then I noticed a typo, so I corrected the address to 8.8.8.8 and ran the line again:
sudo mkdir -p /etc/resolver/ && echo "nameserver 8.8.8.8" | sudo tee /etc/resolver/example.net
But that did not seem to have any effect:
resolver #10
domain : example.net
nameserver[0] : 8.8.8.9
flags : Request A records
reach : Reachable
I checked the file content, all seemed fine:
$ cat /etc/resolver/example.net
nameserver 8.8.8.8
And then I opened the file in vim, changed to 8.8.4.4 and:
resolver #10
domain : example.net
nameserver[0] : 8.8.4.4
flags : Request A records
reach : Reachable
I have checked back and forth several times, when I echo the address to the file, the change has no effect, but it is enough to only open it in vim and not even change anything (just exit), previously echoed changes will be applied.
What is the mechanism behind this?