Testing DNS Speeds

Here are some quick scripts for testing DNS speeds and comparing the results.

Every time there is a new DNS service announced a lot of folk rush to use these new settings because of promises of lightning fast lookup speeds. In this article we will run through some quick and dirty testing you can do to see if a different DNS is right for you.

This article comes off the back of lots of discussion over the new by CloudFlare, one thing we won’t be covering is who you should use. It bares mentioning that speed is not the only thing we should care about from a DNS service. Privacy, security, and ethical behaviour are all things you should take into account.

A quick refresher on DNS

The very quick overview of DNS is that we humans like using domain names (tosbourn.com) but computers need to know which IP address ( that domain name lives on so it knows where to go looking for it.

When you type a domain name into your browser, a DNS’ job is to resolve that name to an IP address.

This is a bit of plumbing that just needs to happen, so the faster it can happen the better.

Location and ISPs

We’re going to look at two different metrics you could use to decide which DNS is faster for you, the reason why you might want to run your own tests instead of reading a blog post explaining the difference is that your speed will be effected by how far away you are from the DNS and how your Internet Service Provider acts.

Ping times

The first thing we can run is ping.

ping lets you send an ECHO_REQUEST to a network host, which is the equivalent of shouting “HELLO WEBSITE.COM” and seeing if it responds.

With ping we can send these requests to the various DNS hosts we want to test and look at the results.

ping -c 5

In the above command we called ping with -c 5, this says “send the request 5 times”. The is the DNS server we’re testing.

Here is the output of that command:

PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=60 time=558.886 ms
64 bytes from icmp_seq=1 ttl=60 time=543.474 ms
64 bytes from icmp_seq=2 ttl=60 time=542.532 ms
64 bytes from icmp_seq=3 ttl=60 time=639.319 ms
64 bytes from icmp_seq=4 ttl=60 time=595.443 ms

The numbers we care about are the ones after time=, we should take an average of them to give the DNS a score for ping times.

ping should work on most Unix and Windows based operating systems.

Dig times

The times given back from ping are really easy to compare but have some issues. A server could decide that responding to ping isn’t that important which would make a DNS look slower than it maybe it. A more realistic speed would come from actually asking that DNS to perform a lookup for us.

dig is a DNS lookup utility. It is purpose built for this type of stuff.

We can call it like so:

dig @ tosbourn.com

What we’re saying here is use as the DNS and lookup tosbourn.com.

Running that command gave me the following output.

; <<>> DiG 9.10.6 <<>> @ tosbourn.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44155
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

; EDNS: version: 0, flags:; udp: 512
;tosbourn.com. IN A

tosbourn.com. 299 IN A
tosbourn.com. 299 IN A

;; Query time: 557 msec
;; WHEN: Mon Apr 02 17:48:11 BST 2018
;; MSG SIZE rcvd: 73

That is a lot of information! We care about Query time. In this example it was 557 msec.

If you wanted to compare several websites (the ones you use most frequently) and several DNS services this could become tiresome. Here is a script that could help:

for domain in twitter.com tosbourn.com bbc.co.uk; do \
 google_dns=$(dig @ ${domain} | awk '/msec/{print $4}');\
 cloudflare_dns=$(dig @ ${domain} | awk '/msec/{print $4}'); \
 printf "${domain}\tCloudFlare DNS ${cloudflare_dns}ms\tGoogle DNS ${google_dns}ms\n";\

This uses some bash scripting to do a for loop, iterating over some websites we care about and assigning them to the temporary variable domain.

For each domain it will create two variables cloudflare_dns and google_dns, these both perform the dig commands and pass their results to a tool called awk which extracts information from output.

Once we have just the numbers we need, we use printf to output a line with our results. When we run that script we will get something like:

twitter.com CloudFlare DNS 475ms Google DNS 606ms
tosbourn.com CloudFlare DNS 640ms Google DNS 577ms
bbc.co.uk CloudFlare DNS 599ms Google DNS 596ms

If all you care about is speed, then the DNS with the lower number for the websites you care about is probably your best bet.

dig should work on most unix based operating systems, for Windows you will need to install it.

Recent posts View all


Cocoon Development Training

We'd highly recommend Cocoon for Apple development and Apple training


Adding issues from other organisations into Github Projects

Let's talk about how you can add issues from other organisations into your Github Project