Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

up vote 2 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 192.168.1.143.61150 > 192.168.1.1.53:
  60237+ A? www-google-analytics.l.google.com. (51)
22:19:46.184272 IP 192.168.1.1.53 > 192.168.1.143.61150:
  60237 11/0/0 A 74.125.225.233, A 74.125.225.238, A 74.125.225.224,
  A 74.125.225.225, A 74.125.225.226, A 74.125.225.227, A 74.125.225.228,
  A 74.125.225.229, A 74.125.225.230, A 74.125.225.231, A 74.125.225.232 (227)

This dump shows a request from my machine to my router (192.168.1.143 > 192.168.1.1) 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 have a latency issue on certain requests to an address on localhost.

When you say "localhost" do you really mean localhost? as in 127.0.0.1 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 127.0.0.1 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.