First, if networksetup -getdnsservers <service name>
does not show anything, you don't have anything listed in System Preferences > Netowrk under "DNS Servers:".
Second, it is important to note that OS X does not handle DNS like most systems. Per https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/resolver.5.html Essentially this means that OS X has multiple DNS clients depending on your configuration. The result of these multiple services means that there are situations whereby using Safari to access a website (http://www.example.com) will take you to an IP address that OS X has retrieved from DNS (say 1.2.3.4) while at the same time, performing a dig
$ dig www.example.com
will return different results. (perhaps 2.3.4.5)
The reason for this lies in the way that OS X handles DNS.
If you run $ man dig
you get among other things, the following:
Mac OS X NOTICE
The dig command does not use the host name and address resolution or
the DNS query routing mechanisms used by other processes running on Mac
OS X. The results of name or address queries printed by dig may differ
from those found by other processes that use the Mac OS X native name
and address resolution mechanisms. The results of DNS queries may also
differ from queries that use the Mac OS X DNS routing library.
Also $man nslookup
will return something similar
Mac OS X NOTICE
The nslookup command does not use the host name and address resolution or the DNS query
routing mechanisms used by other processes running on Mac OS X. The results of name or
address queries printed by nslookup may differ from those found by other processes that
use the Mac OS X native name and address resolution mechanisms. The results of DNS
queries may also differ from queries that use the Mac OS X DNS routing library.
All this is really a rather lengthy way of saying, the best way to see what DNS servers are being used is to look at System Preferences > Network
The "DNS Server:" entires are usually there, and "Search Domains:" will allow you to search for incomplete addresses.
If "DNS Server:" is not present, then OS X will try to use the address in "Router:" for DNS.
AND, on top of all this fun, there are utilities and other processes that may not be using the OS X DNS Routing Library, and they will be hitting the contents of /etc/resolv.conf directly.
The short short answer is this:
- If you go by the contents of System Preferences > Network, you are looking at the same thing that most processes are using.
- The Contents of System Preferences > Network, should populate /etc/resolv.conf, but not always.
- Some other processes (like dig and nslookup) are accessing /etc/resolv.conf directly.
And, on top of all this - If you are not using the VPN clients built in to OS X, it is possible that additional routes and DNS servers are being used that networksetup -getdnsservers <service name>
will not show. Your VPN client may have the ability to show you the routes and DNS servers, I know that mine does.
I know that this does not precisely answer your question, but hopefully this helps you realize that it is not always easy to find out what the "truth" is regarding DNS on a Mac. Generally you are safe assuming that the contents of System Preferences > Network, or the contents of networksetup -getdnsservers <service name>
are where you are getting your DNS from. However if things seem weird, keep in mind that there are other possibilities too. Use dig to help determine if there are differences afoot.
Last, for those readers who are wondering how to get the <service name>
in networksetup -getdnsservers <service name>
, try using networksetup -listallnetworkservices
Bill
Best Answer
First:
nslookup
does not use the system DNS resolver, and does not behave the same way that the system resolver does. Neither dodig
orhost
, so none of these tools are useful for checking how macOS resolves names. If you want to use the system resolver, usedscacheutil -q host -a name google.com
, but note that it uses the entire resolution system -- it looks in the local cache, /etc/hosts, mDNS (for .local names), and then DNS. Oh, and the man page fordscacheutil
claims it can flush the DNS cache, but it doesn't work; usesudo killall mDNSResponder
instead.Second: the system resolver does not do a good (or even adequate) job of failing over between DNS servers. If you list multiple servers, it'll fire off queries to all of them in a sort of randomized-round-robin fashion. If it doesn't get a response, it'll eventually time out and try the other one. If it gets a "that doesn't exist" response, it assumes that's correct and doesn't try any other server. As a result, you really need a single server that can answer all queries, both internal and external.
Ok, there's one possible workaround: you can point your system at a public DNS server, then create /etc/resolver/ and put files in it to redirect queries for certain domains to your internal server. Provided you know what domains to redirect, that is. See Apple.SE: "Do /etc/resolver/ files work in Mountain Lion for DNS resolution?".