Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a latency issue on certain requests to an address on localhost. I suspect there's something going on with the DNS lookup.

Is there a way that I can profile DNS lookup on OSX? For example, is there a log I can watch as it tries to do the lookups?

share|improve this question
up vote 6 down vote accepted

You could just run tcpdump to dump DNS packets and look at how DNS traffic is behaving. Something like the following, entered in Terminal, should do the trick:

sudo tcpdump -i en0 -n udp port 53

The -i en0 should reference your active interface. On Macs, this is usually en0, but if you have both an ethernet jack and a wireless adapter, you might need to use en1. This will produce output like (I've wrapped long lines for clarity):

22:19:46.160992 IP >
  60237+ A? (51)
22:19:46.184272 IP >
  60237 11/0/0 A, A, A,
  A, A, A, A,
  A, A, A, A (227)

This dump shows a request from my machine to my router ( > at 22:19:46.160992. My router replied back at 22:19:46.184272 with the response. So this DNS request took about 23ms.

If you suspect a DNS performance problem, run the tcpdump command and look for the DNS requests for the server which interests you. If you see a long delay or several tries, then you know you have a problem.

share|improve this answer
I think its -i eth0 for regular linux. :+1: – ThorSummoner Jun 16 '15 at 17:36

I have a latency issue on certain requests to an address on localhost.

When you say "localhost" do you really mean localhost? as in or ::1?

You can use tcpdump to look for resolver traffic as the previous poster has suggested but if you literally mean localhost there's a quite good chance the name isn't even being resolved using DNS.

share|improve this answer
I do mean localhost as you said. However, because I have several apps running locally, I access it via something like fooapp.local, which should be resolved to localhost. Our in-office DNS resolves that address to and I also have an entry in /etc/hosts. Actually, two entries: one for IPv4 and one for IPv6. – Nathan Long Feb 7 '13 at 13:13
If it's in your hosts file, then the stub resolver is probably not using DNS. However, I am not positive about the resolution order used by MacOS 10.8's stub resolver so it would be best to check (using the tcpdump method suggested by hrunting.) – Michael McNally Feb 7 '13 at 17:42

You must log in to answer this question.

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