The latency of DNS is usually an important factor in the Internet speed perception the user has. The faster the DNS respond to you the better browsing experience you will have.

But usually all DNS servers are fast enough, the only problem you will have is how far you are from them, and how much the round trip takes. You may know that your query needs to travel all the way to the server, and then back to you.

Today I have stumbled upon a nice one line script to find out which DNS server has the smallest query duration for you.

I have written in the past some articles about how to install local DNS server, using both dnsmasq and pdnsd.

How to determine the faster DNS query time

x=0; server=; host=""; queries=128; for i in `seq $queries`; do let x+=`dig @${server} $host | grep "Query time" | cut -f 4 -d " "`; done && echo "scale=3;($x/${queries})" | bc

What this line is doing is running a bash for loop, to query $queries times, to the $server, looking for the $host and then getting a prom of the query times.

Here are results for me:

  • Using 138.539 ms
  • Using 122.562 ms
  • Using Local DNS: 83.179 ms

Now the on line script is really interesting, but maybe not needed, as with a single ping you may get the same information.

Ping time responses to the same servers are:

  • To ping -c 50 -> Average: 140.704 ms
  • To ping -c 50 -> Average: 125.889 ms
  • To Local DNS: ping -c 50 -> Average 89.941 ms

Do you see how similar results we got from the script and from a simple ping?

And finally, I have discovered namebench, and after running it, these are the results.

  • Is the best
  • Second place
  • Worst

But this is because it used, my Firefox history, so being my local DNS just queried by my co-workers it has its cache almost empty and as I am in Bolivia, it had to query root server for each query it does not have.

Read more about namebench here


All you need, is to use the closest DNS server you can use, provided it is stable.

One last consideration, if you are going to query new pages all time, then the cache the server has is also relevant, I mean, if you are the only user of your local DNS or it has too few users, and each query is for a new IP, you have nothing to win by being near it, as every query you make to it, it will have to query root servers. Now if you query the same pages all over and over, then the closer is the better. I’m sure you got the picture.

By the way, the credit for that one line script goes to: Debiania.