How do I add locally hosted DNS server while preserving default LAN DNS
I eventually devised this script to keep a separate resolv.conf file for dnsmasq that is updated on network changes.
#!/usr/local/bin/bash

mkfifo P
exec 3&gt;P # open file descriptor 3 writing to the pipe
scutil &lt; P | fgrep notification | \
    xargs -L 1 bash -c 'echo &quot;nameserver $(ipconfig getoption $(route -n get default | fgrep interface | awk &quot;{print \$2}&quot;) domain_name_server)&quot; &gt; /usr/local/etc/dnsmasq.d/resolv-dnsmasq.conf'
echo -e &quot;n.add State:/Network/Global/IPv4\nn.watch&quot; &gt; P

I may need to add in a dnsmasq restart too, depending on testing results.