135

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.

3
  • 1
    When you use dig or nslookup command, it shows default DNS server IP address.
    – Biswapriyo
    Jul 21, 2017 at 20:23
  • 2
    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, 2017 at 23:26
  • See also superuser.com/questions/536238/…
    – caw
    May 7, 2020 at 16:11

6 Answers 6

220

You could try issuing the following at the command line:

scutil --dns | grep 'nameserver\[[0-9]*\]'

It should give you a list of DNS servers configured on your system.

7
  • 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, 2011 at 4:14
  • 2
    +1 For a command that shows the servers for “multi-client” configurations (e.g. /etc/resolver/…). Mar 16, 2011 at 4:37
  • 3
    I've added | sort | uniq to it as I was only interested in the unique DNS servers used. Aug 23, 2015 at 6:11
  • 2
    Nitpick, but why is it necessary to add \[[0-9]*\] to the grep string?
    – ijoseph
    Nov 22, 2017 at 21:13
  • 2
    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, 2018 at 10:09
26

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
2
  • 1
    This will show the same thing that System Preferences > Network does. Dec 16, 2013 at 19:14
  • 4
    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. Apr 21, 2017 at 23:59
23

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

dnsleaktest.com provides the same results via a web interface.

The IP address returned by these tools is a DNS resolver in use for your network, but may be only one of several.

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

2
  • 1
    Excellent. This saves the time of accessing the router admin screen.
    – downeyt
    May 19, 2015 at 14:29
  • This service is great.
    – pedrosanta
    Oct 25, 2016 at 13:56
20

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.

3
  • 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, 2018 at 0:10
  • 2
    @senfo No, Jacob is right, many routers advertise themselves as the DNS server via DHCP, and internally, they query a real (recursive) DNS server.
    – caw
    May 7, 2020 at 16:10
  • 3
    @caw, I've gone back and read the comment and I think I misunderstood what the original answer was getting at. I retract my former judgement of this answer.
    – senfo
    May 7, 2020 at 16:47
8

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
4
  • Command not working in 2022 with Monterey. Would have been nice. Jul 21, 2022 at 13:30
  • I have not Monterey on my machine. Is ipconfig getoption en1 domain_name_server works? Where "en1" is one of interfaces listed by ifconfig -l. Jul 21, 2022 at 18:02
  • ipconfig command above doesn't give any feedback at all. ifconfig -l gives this feedback: lo0 gif0 stf0 anpi0 anpi1 anpi2 en4 en5 en6 en1 en2 en3 ap1 en0 awdl0 llw0 bridge0 utun0 utun1 utun2. I'm only running Monterey as it's the oldest OS which the MBP M1 Pro series will run. Jul 22, 2022 at 0:47
  • networksetup -listallnetworkservices and networksetup -getdnsservers Wi-Fi
    – eccstartup
    May 10, 2023 at 6:49
4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .