How do I check what DNS server I'm using (on Mac OS X)

75

25

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.

ryanprayogo

Posted 2011-03-16T03:26:31.630

Reputation: 1 235

When you use dig or nslookup command, it shows default DNS server IP address. – Biswapriyo – 2017-07-21T20:23:46.980

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 – 2017-12-31T23:26:12.220

Answers

116

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.

GhettoSA

Posted 2011-03-16T03:26:31.630

Reputation:

2I've added | sort | uniq to it as I was only interested in the unique DNS servers used. – Jeroen Wiert Pluimers – 2015-08-23T06:11:25.730

1Nitpick, but why is it necessary to add \[[0-9]*\] to the grep string? – ijoseph – 2017-11-22T21:13:54.863

1On my computer scutil --dns | grep nameserver is enough, or scutil --dns | grep nameserver | sort -u if I just want to see unique servers. – AllanLRH – 2018-04-16T10:09:04.880

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 – 2011-03-16T04:14:47.000

2

+1 For a command that shows the servers for “multi-client” configurations (e.g. /etc/resolver/…).

– Chris Johnsen – 2011-03-16T04:37:25.623

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.

Jacob

Posted 2011-03-16T03:26:31.630

Reputation: 1 614

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 – 2018-03-12T00:10:00.793

10

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

user1908924

Posted 2011-03-16T03:26:31.630

Reputation: 159

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 – 2017-04-21T23:59:56.930

1This will show the same thing that System Preferences > Network does. – Kevin Panko – 2013-12-16T19:14:39.633

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.

Quinn Comendant

Posted 2011-03-16T03:26:31.630

Reputation: 771

Excellent. This saves the time of accessing the router admin screen. – downeyt – 2015-05-19T14:29:35.370

This service is great. – pedrosanta – 2016-10-25T13:56:42.953

5

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

Hamid Rohani

Posted 2011-03-16T03:26:31.630

Reputation: 155

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.

becomingwisest

Posted 2011-03-16T03:26:31.630

Reputation: 221