Pretty self-explanatory.
A Little script to test a handful of DNS resolvers.
(pings wikipedia.org by default)
Intended for those interested in such information, such as those preparing optimizations, or for educational purposes.
Please let me know of any problems or if there is a DNS provider you think should be included.
Note: requires package bind
dns-speed-test.sh
#!/bin/env bash
#
# dns speed test
#
if [[ -z "$DOMAIN" ]]; then
DOMAIN=wikipedia.org
fi;
CURRENTDNS=$(dig "$DOMAIN" | grep SERVER | awk -F'[)(]' '{print $2}')
if [[ -z "$SKIP" ]]; then
echo
echo " Test common resolvers by calculating average response times of 3 queries."
echo
annc() {
echo
echo " DNS Primary Secondary"
echo
echo " Adguard 94.140.14.14 94.140.15.15"
echo " Comodo 8.26.56.26 8.20.247.20"
echo " Control-D 76.76.2.2 76.76.10.2"
echo " Cloudflare 1.1.1.1 1.0.0.1"
echo " CyberGhost 38.132.106.139 194.187.251.67"
echo " Google 8.8.8.8 8.8.4.4"
echo " Neustar 156.154.70.5 156.154.71.2"
echo " NextDNS 45.90.28.97 45.90.30.97"
echo " OpenDNS 208.67.222.222 208.67.220.220"
echo " Quad9 9.9.9.9 149.112.112.112"
echo
}
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
annc | column -tL
fi;
if [[ -n "$TESTDNS" ]]; then
echo "Custom Test DNS $TESTDNS"
fi
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo
while true; do
read -p " Do you wish to flush the DNS cache? " yn
case $yn in
[Yy]* ) resolvectl flush-caches; break;;
[Nn]* ) break;;
* ) echo -e "\n Please answer yes or no.\n";;
esac
done
echo
echo "Current DNS $CURRENTDNS"
for reps in {1..3}
do
dig "$DOMAIN" | awk '/time/ {print $4 " ms"}'
sleep 1
done | awk '/ms/ {sum+=$1} END {print "Avg time: ",sum/3, " ms"}'
echo
if [[ -z "$SKIP" ]]; then
rank() {
for resolver in "Adguard 94.140.14.14" "Comodo 8.26.56.26" "Control-D 76.76.2.2" "Cloudflare 1.1.1.1" "CyberGhost 38.132.106.139" "Google 8.8.8.8" "Neustar 156.154.70.5" "NextDNS 45.90.28.97" "OpenDNS 208.67.222.222" "Quad9 9.9.9.9";
do
echo $resolver
for reps in {1..3}
do
dig "$DOMAIN" "@${resolver#* }" | awk '/time/ {print $4 " ms"}'
sleep 1
done | awk '/ms/ {sum+=$1} END {print "Avg time: ",sum/3, " ms"}'
echo
done
}
rank;
fi;
if [[ -n "$TESTDNS" ]]; then
echo "Custom Test DNS $TESTDNS"
for reps in {1..3}
do
dig "$DOMAIN" "@$TESTDNS" | awk '/time/ {print $4 " ms"}'
sleep 1
done | awk '/ms/ {sum+=$1} END {print "Avg time: ",sum/3, " ms"}'
echo
fi
exit
How to use
-
Create a text file containing the above data and saved as
dns-speed-test.sh
-
Mark executable
chmod +x dns-speed-test.sh
-
Run
./dns-speed-test.sh
-
(Optional) Add your own DNS for testing
TESTDNS=176.103.130.130 ./dns-speed-test.sh
-
(Optional) Set your own target URL
DOMAIN=manjaro.org ./dns-speed-test.sh
-
(Optional) Set SKIP variable to avoid running default sample tests
SKIP=1 TESTDNS=1.1.1.1 ./dns-speed-test.sh
Edit/Update:
- Removed extra DNS samples
- Added $TESTDNS variable to allow extra DNS test on the fly.
- Added $DOMAIN variable to allow setting ping test target URL.
- Added $SKIP variable to avoid pinging sample DNS resolvers.
- Added new resolvers