Get DNS Server IP Addresses from the Command Line in Mac OS X

Jun 3, 2011 - 3 Comments

You can quickly retrieve active DNS server IP addresses on any Mac by using the networksetup utility. Launch the Terminal and type the following:

Mac OS X 10.7 Lion:
networksetup -getdnsservers Wi-Fi

Mac OS X 10.6 Snow Leopard and before:
networksetup -getdnsservers airport

Note that I’m specifying ‘airport’ because I primarily use a wireless connection, but you could also specify ethernet and bluetooth.

Assuming there are several DNS servers set within Mac OS X’s networking preferences, you will see a report of each DNS server in the order of their priority, looking something like this:

8.8.8.8
208.67.220.220
208.67.222.222
10.0.0.1

For those wondering, the top most DNS IP in that sample list is Google’s Public DNS, the next two are from OpenDNS, with the last being a local router. If you need to, you can use a free utility like namebench to find a fast DNS server.

Related articles:

Posted by: David Mendez in Command Line, Mac OS X

3 Comments

» Comments RSS Feed

  1. c3dr1k says:

    Nice tip. Google’s DNS is surprisingly slow in benchmarks, but I would rather use Google than OpenDNS.

  2. monsi says:

    I never thought about using networksetup for this but you can also get the same result by simply looking at nslookup:

    $ nslookup
    > server
    Default server: 8.8.8.8
    Address: 8.8.8.8#53
    Default server: 4.2.2.1
    Address: 4.2.2.1#53

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

OSXDaily on Facebook

OSXDaily on Google+

Shop at Amazon

Ad

Shared on Facebook