networking:dns:dns_performance_tests
Table of Contents
Networking - DNS - DNS Performance Tests
Determine which DNS server is the quickest to use.
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.
Required
You need to install bc and dig. For Ubuntu:
sudo apt-get install bc dnsutils
Install
git clone --depth=1 https://github.com/cleanbrowsing/dnsperftest/
or manually create the following file, make it executable and run it:
- dnstest.sh
#!/usr/bin/env bash command -v bc > /dev/null || { echo "bc was not found. Please install bc."; exit 1; } { command -v drill > /dev/null && dig=drill; } || { command -v dig > /dev/null && dig=dig; } || { echo "dig was not found. Please install dnsutils."; exit 1; } NAMESERVERS=`cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2 | sed 's/\(.*\)/&#&/'` PROVIDERS=" 192.168.1.1#pfSense 192.168.1.2#Bind Server 1.1.1.1#cloudflare 4.2.2.1#level3 8.8.8.8#google 9.9.9.9#quad9 80.80.80.80#freenom 208.67.222.123#opendns 199.85.126.20#norton 185.228.168.168#cleanbrowsing 77.88.8.7#yandex 176.103.130.132#adguard 156.154.70.3#neustar 8.26.56.26#comodo " # Domains to test. Duplicated domains are ok DOMAINS2TEST="www.google.com amazon.com facebook.com www.youtube.com www.reddit.com wikipedia.org twitter.com gmail.com www.google.com whatsapp.com" totaldomains=0 printf "%-18s" "" for d in $DOMAINS2TEST; do totaldomains=$((totaldomains + 1)) printf "%-8s" "test$totaldomains" done printf "%-8s" "Average" echo "" for p in $NAMESERVERS $PROVIDERS; do pip=${p%%#*} pname=${p##*#} ftime=0 printf "%-18s" "$pname" for d in $DOMAINS2TEST; do ttime=`$dig +tries=1 +time=2 +stats @$pip $d |grep "Query time:" | cut -d : -f 2- | cut -d " " -f 2` if [ -z "$ttime" ]; then #let's have time out be 1s = 1000ms ttime=1000 elif [ "x$ttime" = "x0" ]; then ttime=1 fi printf "%-8s" "$ttime ms" ftime=$((ftime + ttime)) done avg=`bc -lq <<< "scale=2; $ftime/$totaldomains"` echo " $avg" done exit 0;
Run
cd dnsperftest bash ./dnstest.sh
returns:
test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 Average 127.0.0.53 9 ms 9 ms 9 ms 14 ms 19 ms 20 ms 9 ms 14 ms 1 ms 9 ms 11.30 Peter 1 ms 1 ms 1 ms 1 ms 1 ms 1 ms 1 ms 1 ms 1 ms 1 ms 1.00 cloudflare 8 ms 10 ms 8 ms 8 ms 11 ms 9 ms 8 ms 9 ms 8 ms 8 ms 8.70 level3 13 ms 14 ms 14 ms 14 ms 14 ms 13 ms 14 ms 13 ms 13 ms 14 ms 13.60 google 7 ms 7 ms 19 ms 12 ms 18 ms 19 ms 7 ms 13 ms 7 ms 12 ms 12.10 quad9 20 ms 18 ms 23 ms 22 ms 14 ms 120 ms 15 ms 20 ms 16 ms 23 ms 29.10 freenom 25 ms 35 ms 20 ms 46 ms 42 ms 148 ms 25 ms 25 ms 22 ms 121 ms 50.90 opendns 8 ms 8 ms 8 ms 25 ms 8 ms 112 ms 8 ms 25 ms 13 ms 9 ms 22.40 norton 8 ms 8 ms 8 ms 8 ms 8 ms 8 ms 8 ms 8 ms 8 ms 8 ms 8.00 cleanbrowsing 19 ms 15 ms 14 ms 18 ms 19 ms 18 ms 14 ms 14 ms 14 ms 14 ms 15.90 yandex 47 ms 76 ms 47 ms 47 ms 47 ms 160 ms 47 ms 52 ms 47 ms 47 ms 61.70 adguard 19 ms 18 ms 18 ms 19 ms 14 ms 14 ms 14 ms 18 ms 14 ms 20 ms 16.80 neustar 20 ms 20 ms 22 ms 20 ms 21 ms 22 ms 24 ms 21 ms 22 ms 20 ms 21.20 comodo 14 ms 15 ms 13 ms 15 ms 13 ms 128 ms 14 ms 14 ms 15 ms 16 ms 25.70
NOTE: To sort with the fastest first, add | sort -k 22 -n at the end of the command:
dnstest.sh | sort -k 22 -n
For Windows users using the Linux subsystem
If you receive an error $'\r': command not found, convert the file to a Linux-compatible line endings using:
tr -d '\15\32' < dnstest.sh > dnstest-2.sh
Then run bash ./dnstest-2.sh
Use Docker to run the DNS performance test
Have a Dockerfile
Dockerfile contains the following:
- Dockerfile
FROM alpine:latest RUN apk --no-cache add bash bc drill \ && mkdir /app \ && wget https://raw.githubusercontent.com/cleanbrowsing/dnsperftest/master/dnstest.sh -O /app/dnstest.sh \ && chmod +x /app/dnstest.sh ENTRYPOINT ["/app/dnstest.sh"]
Build the Docker image
docker build --tag dnstest .
returns:
Sending build context to Docker daemon 83.46kB Step 1/3 : FROM alpine:latest latest: Pulling from library/alpine aad63a933944: Pull complete Digest: sha256:b276d875eeed9c7d3f1cfa7edb06b22ed22b14219a7d67c52c56612330348239 Status: Downloaded newer image for alpine:latest ---> a187dde48cd2 Step 2/3 : RUN apk --no-cache add bash bc drill && mkdir /app && wget https://raw.githubusercontent.com/cleanbrowsing/dnsperftest/master/dnstest.sh -O /app/dnstest.sh && chmod +x /app/dnstest.sh ---> Running in a8c11400d24c fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz (1/7) Installing ncurses-terminfo-base (6.1_p20200118-r3) (2/7) Installing ncurses-libs (6.1_p20200118-r3) (3/7) Installing readline (8.0.1-r0) (4/7) Installing bash (5.0.11-r1) Executing bash-5.0.11-r1.post-install (5/7) Installing bc (1.07.1-r1) (6/7) Installing ldns (1.7.1-r1) (7/7) Installing drill (1.7.1-r1) Executing busybox-1.31.1-r9.trigger OK: 8 MiB in 21 packages Connecting to raw.githubusercontent.com (151.101.64.133:443) saving to '/app/dnstest.sh' dnstest.sh 100% |********************************| 1582 0:00:00 ETA '/app/dnstest.sh' saved Removing intermediate container a8c11400d24c ---> f04a1f625386 Step 3/3 : ENTRYPOINT ["/app/dnstest.sh"] ---> Running in f23f9090e44f Removing intermediate container f23f9090e44f ---> 2d50dc06d819 Successfully built 2d50dc06d819 Successfully tagged dnstest:latest
Run the Docker image
docker run dnstest
References
networking/dns/dns_performance_tests.txt · Last modified: 2021/01/07 12:12 by peter