Dnsdig - A script to measure response times of DNS resolvers

Information on how to use, including remotely, is detailed at the gitlab source.

By default it will test a handful of common resolvers, your currently configured resolver, and can optionally run tests against custom resolvers or upon custom domains.

Thought this was already posted but recent threads reminded me to look and find apparently it was never shared. So here we are.

As always feedback is welcome.

For feedback only:

โ•ญโ”€โ–‘โ–’โ–“ ๏…ผ ๎‚ฐ ๏€• ~ โ–“โ–’โ–‘โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–‘โ–’โ–“ โœ” ๎‚ฒ at 06:45:45 AM ๏€— โ–“โ–’โ–‘โ”€โ•ฎ
โ•ฐโ”€ ./dnsdig                                                                                               โ”€โ•ฏ

 Test common resolvers by calculating average response times of 3 queries.

-------------------------------------------------------------------------------------------------------------                                  
                              
DNS               Primary         Secondary        
Surfshark         151.236.14.64   62.216.95.100   
AdGuard           94.140.14.14    94.140.15.15     
CleanBrowsing     185.228.168.9   185.228.169.9    
Cloudflare        1.1.1.1         1.0.0.1          
Comodo            8.26.56.26      8.20.247.20      
Control-D         76.76.2.2       76.76.10.2       
dns0.eu           193.110.81.0    185.253.5.0      
Dyn/Oracle        216.146.35.35   216.146.36.36    
Gcore             95.85.95.85     2.56.220.2       
Google            8.8.8.8         8.8.4.4          
Level3/Lumen      209.244.0.3     209.244.0.4      
Mullvad           194.242.2.2     194.242.2.3      
NextDNS           45.90.28.105    45.90.30.105     
OpenDNS/Cisco     208.67.222.222  208.67.220.220   
Quad9             9.9.9.9         149.112.112.112  
UltraDNS/Vercara  64.6.64.6       64.6.65.6        
                                                   

                                  
-------------------------------------------------------------------------------------------------------------

 Do you wish to flush the DNS cache (y/N)? y

Current DNS 127.0.0.53
Avg time:  20.3333 ms

Comodo 8.26.56.26
Avg time:  58 ms

Control-D 76.76.2.2
Avg time:  58 ms

Cloudflare 1.1.1.1
Avg time:  58.3333 ms

AdGuard 94.140.14.14
Avg time:  59 ms

dns0.eu 193.110.81.0
Avg time:  59 ms

Gcore 95.85.95.85
Avg time:  59 ms

Mullvad 194.242.2.2
Avg time:  59 ms

CleanBrowsing 185.228.168.9
Avg time:  59.3333 ms

Level3/Lumen 209.244.0.3
Avg time:  59.3333 ms

Quad9 9.9.9.9
Avg time:  59.3333 ms

Google 8.8.8.8
Avg time:  59.6667 ms

NextDNS 45.90.28.105
Avg time:  59.6667 ms

UltraDNS/Vercara 64.6.64.6
Avg time:  59.6667 ms

Dyn/Oracle 216.146.35.35
Avg time:  60 ms

OpenDNS/Cisco 208.67.222.222
Avg time:  61.6667 ms

โ•ญโ”€โ–‘โ–’โ–“ ๏…ผ ๎‚ฐ ๏€• ~ โ–“โ–’โ–‘โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–‘โ–’โ–“ โœ” ๎‚ฒ took 14s ๏‰’ ๎‚ฒ at 06:46:17 AM ๏€— โ–“โ–’โ–‘โ”€โ•ฎ
โ•ฐโ”€                                                                                             

I like this one better than mine. (Nice little script) :100:)
NOTE to readers I added Surfshark to the script for me.

Thanks for the script, it works well!
Would it be possible to add support for testing DNS-over-TLS servers?
I was getting noticeable lag when using DoH in Firefox, so I set up my own Unbound resolver using DoT.

Hm.
Nice request ..
This may end up being a new option as well as an additional part of the table.

For now you can use the TESTDNS env var and a TLS address should be supported, ex;

TESTDNS=p0.freedns.controld.com dnsdig

But while it will succeed it may still just use UDP.

Oh and in case anyone was wondering; QUIC is not supported. This is just how dig and drill are at the moment as far as I know.

Couldnโ€™t resistโ€ฆ TLS servers and tests.
Changed servers, added +TLS and timeout=3. :wink:
EDIT: Refined the multithreaded version (with AI assistance)

#!/usr/bin/env bash
#
# dns speed test
#
# <3 cscs <3
#

DOMAIN="${1:-wikipedia.org}"
THREADS=30  
REPS=3

resolvers=(
"Quad9 9.9.9.9"
"Quad9-alt 149.112.112.112"
"Cloudflare 1.1.1.1"
"Cloudflare-alt 1.0.0.1"
"Google 8.8.8.8"
"Google-alt 8.8.4.4"
"DNS4EU-Unfiltered 86.54.11.100"
"DNS4EU-Protective 86.54.11.1"
"DNS4EU-Protective-Child 86.54.11.12"
"DNS4EU-Protective-Adblock 86.54.11.13"
"DNS4EU-Protective-Child-Adblock 86.54.11.11"
"CleanBrowsing-Family 185.228.168.168"
"CleanBrowsing-Adult 185.228.168.10"
"CleanBrowsing-Security 185.228.168.9"
"AdGuardDNS 94.140.14.14"
"AdGuardDNS-alt 94.140.15.15"
"AdGuardDNS-Family 94.140.14.15"
"AdGuardDNS-Family-alt 94.140.15.16"
"OpenDNS-Cisco 208.67.222.222"
"OpenDNS-Cisco-alt 208.67.220.220"
"OpenDNS-FamilyShield 208.67.222.123"
"OpenDNS-FamilyShield-alt 208.67.220.123"
"NextDNS 45.90.28.0"
"NextDNS-alt 45.90.30.0"
"Mullvad 45.90.28.105"
)

spinner(){ while :; do for c in / - \\ \|; do printf '%s\b' "$c"; sleep 0.1; done; done; }; spinner & SPINNER_PID=$!; trap 'kill $SPINNER_PID 2>/dev/null' EXIT

printf '%s\n' "${resolvers[@]}" |
xargs -P"$THREADS" -I{} bash -c '
resolver="$1"
domain="$2"
reps="$3"
sum=0
count=0

for ((i=0;i<reps;i++)); do
    out=$(dig "$domain" "@${resolver#* }" +tls +timeout=1 +tries=1 2>/dev/null | awk '\''/Query time/ {print $4}'\'')
    if [[ -n "$out" ]]; then
        sum=$((sum + out))
        count=$((count + 1))
    fi
done

name="${resolver%% *}"
rest="${resolver#* }"

if (( count > 0 )); then
    avg=$(( (sum + count/2)/count ))
    printf " %6d ms  %-40s %s\n" "$avg" "$name" "$rest"
else
    printf " %9s  %-40s %s\n" "error" "$name" "$rest"
fi
' _ {} "$DOMAIN" "$REPS" | sort

kill "$SPINNER_PID" 2>/dev/null; wait "$SPINNER_PID" 2>/dev/null

Thanks again for the interest and suggestions.

Updates have been had.

With some features that may be notable to users;

  • Now supports dog (in addition to dig and drill)
  • DOTLS=1 env var to use DNS-over-TLS (drill does not support it)
  • Basic bash multiprocess implemented

It should be observably quicker in all examples.

Get the new version from the gitlab link above of course.

EDIT.

Oh yeah and also;

  • Now supports kdig (in addition to dig, dog, and drill)

Accept my hat tip to you, nice additional script. :+1:

With extra interest in DNS due to the new Welcome/Hello buttons..

Now is maybe a good time to post an update.

DODOT and DODOH env vars are now more clear about enabling DoT and DoH respectively.
And they work as they are supposed to. :wink:

Some other minor bits like an option to just print the index as well as a warning that the aforementioned encryption options will likely generate an error for local resolvers.

As always the update can be got by visiting the source again.