68

In Mac OS X, how do I check what DNS server I'm currently using (preferably a command line solution)?

System Preferences > Network shows 192.168.1.1, which is my router's address and not the real DNS server.

migrated from serverfault.com Mar 16 '11 at 3:39

This question came from our site for system and network administrators.

  • When you use dig or nslookup command, it shows default DNS server IP address. – Biswapriyo Jul 21 '17 at 20:23
  • For the record - your router has a real DNS server. In greater detail, it's a recursing DNS server, same as your ISP's DNS or Google's 8.8.8.8. – Nowaker Dec 31 '17 at 23:26
108

You could try issuing a scutil --dns | grep 'nameserver\[[0-9]*\]' at the command line. Should give you a list of DNS servers configured on your system.

  • that's a great command - it looks like that is the DNS server used by Comcast (my ISP). +1 for a great bonus point and what appears to be a deeper knowledge answer. – mbb Mar 16 '11 at 4:14
  • 2
    +1 For a command that shows the servers for “multi-client” configurations (e.g. /etc/resolver/…). – Chris Johnsen Mar 16 '11 at 4:37
  • 2
    I've added | sort | uniq to it as I was only interested in the unique DNS servers used. – Jeroen Wiert Pluimers Aug 23 '15 at 6:11
  • 1
    Nitpick, but why is it necessary to add \[[0-9]*\] to the grep string? – ijoseph Nov 22 '17 at 21:13
  • On my computer scutil --dns | grep nameserver is enough, or scutil --dns | grep nameserver | sort -u if I just want to see unique servers. – AllanLRH Apr 16 '18 at 10:09
16

Your router is acting as a DNS forwarder, you ask your router and your router asks a DNS server for you. You need to login to your router web config to figure out what it's using, or you could just enter it directly into your Network configuration.

  • This is simply wrong. A DHCP server assigns a DNS server (which is what I think you're being confused by), but a router doesn't handle DNS on its own. Its job is to route traffic. – senfo Mar 12 '18 at 0:10
10

Akamai provides a DNS debugging tool which returns the IP address of the resolver used for the query. Open Terminal.app and run the following command:

dig whoami.akamai.net +short

UltraDNS also provides one, but I've found it to be less reliable:

dig whoami.ultradns.net +short

The IP address returned by these tools is a DNS resolver in use for your network, but may be only one of several. There might be an advantage to using the IP in your Network preferences directly.

You can benchmark the performance of your local and alternate DNS servers using namebench.

  • Excellent. This saves the time of accessing the router admin screen. – downeyt May 19 '15 at 14:29
  • This service is great. – pedrosanta Oct 25 '16 at 13:56
9

Use the following command to view your DNS server in Mac OS X :

Open the terminal and type

$ cat /etc/resolv.conf

to view your DNS server.

Sample output :

$ cat /etc/resolv.conf 
domain http://www.example.com (Here, you can see DNS records info of the particular domain name.)
nameserver 68.87.85.98
nameserver 68.87.69.146
  • 1
    This will show the same thing that System Preferences > Network does. – Kevin Panko Dec 16 '13 at 19:14
  • Not too useful nowadays. That file is only so legacy applications have something to read. Most of the MacOS stuff uses an internal database. See the reply above using the "scutil" command. – Chris Cogdon Apr 21 '17 at 23:59
3

That is the DNS server your mac is using. Your router is running a caching DNS server, and setting itself as the DNS server via DHCP. If you login to your router, you might be able to find out which DNS servers it uses.

3

I reached to this question while I was looking for a way to get the list of DNS servers of a specific network adapter in text format (for example the Wi-Fi adapter):

enter image description here

This DNS servers list can be obtained in the terminal with this command:

$ networksetup -getdnsservers Wi-Fi
8.8.8.8
4.2.2.4
4.2.2.1
4.2.2.2
192.168.1.1

And for Ethernet adapter:

$ networksetup -getdnsservers Ethernet
8.8.8.8
4.2.2.4
4.2.2.1
4.2.2.2
192.168.1.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.