I know how to query DNS using tools like dig
, host
, etc. But their macOS man pages state:
The results of DNS queries may also differ from queries that use the macOS DNS routing library.
Given that, how do I query DNS in terminal and get the same results as native macOS apps?
When testing DNS changes I sometimes see different results between the unix tools and native mac applications. Here is an example of what I've encountered:
$ dig +short example.com
192.168.0.100
dig shows that the DNS query returns a local address handled by our own DNS server. Meanwhile using the macOS 'Network Utility' lookup returns a cached result:
using the macOS network reachability tool, I get a cached result as well (for those not familiar with the output the IP address is revealed in the last line):
$ scutil -W -r example.com
0: direct
<SCNetworkReachability 0x7f8a39605ab0 [0x7fffa3c088f0]> {name = example.com}
Reachable
1: start
<SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com}
2: on runloop
<SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (DNS query active), flags = 0x00000002, if_index = 13}
Reachable
*** 13:08:23.373
3: callback w/flags=0x00000002 (info="by name")
<SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (complete, 93.184.216.34, 2606:2800:220:1:248:1893:25c8:1946), flags = 0x00000002, if_index = 13}
Reachable
Is there a macOS command line utility to resolve addresses using the same heuristic that native mac apps use? Note: I am not interested in clearing the DNS cache, I'm interested in using the native macOS DNS resolver from a script. I've looked at man pages for mDNSResponder
, dns-sd
, scutil
, networksetup
, and dscacheutil
none of which seem to query dns.