Get DNS Server IP Addresses from the Command Line in Mac OS X
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.

Nice tip. Google’s DNS is surprisingly slow in benchmarks, but I would rather use Google than OpenDNS.
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
Command in OS X Lion is:
networksetup -getdnsservers Wi-Fi
Because Airport = Wi-Fi just renamed