Mac OS X: finding the DNS servers available
Posted by jpluimers on 2016/07/01
DNS and Mac OS X are a bit of a tricky situation as OS X can use more than the default DNS servers: its resolve can do a multi-client DNS search.
The default DNS servers can be listed like this:
scutil --dns | grep 'nameserver\[[0-9]*\]' | sort | uniq
The effective DNS server like this:
dig whoami.akamai.net | grep "^;; SERVER" | cut -c 12-
Sometimes you want to know if you have manually configured DNS servers, or only DHCP assigned ones. This statement shows that for my Wi-Fi network-service:
networksetup -getdnsservers Wi-Fi
Because of the multi-client setup, you need to run this for all network-services configured on your OS X installation. You can get the list like this:
networksetup -listallnetworkservices
I’ve not yet found a way to list only active services, as the networksetup documentation indicates the -listnetworkserviceorder option will mark inactive ones with (*), but it reality does so only for disabled ones. So this does not work:
networksetup -listnetworkserviceorder
I might one day dig into combining the output of ifconfig with networksetup to figure out a shell based solution to this question.
–jeroen






Leave a comment