Skip to content

Instantly share code, notes, and snippets.

@michele-tn
Created August 9, 2025 13:51
Show Gist options
  • Save michele-tn/cb3ea408de612b897c2a5f6ede256a51 to your computer and use it in GitHub Desktop.
Save michele-tn/cb3ea408de612b897c2a5f6ede256a51 to your computer and use it in GitHub Desktop.

DNS Speed Test Script

A simple Bash script to measure and compare DNS query response times from popular public DNS servers.
Outputs aligned ASCII tables showing raw and sorted results by speed.


Tested Environment

This script has been tested on the following Linux distribution:

  • Distributor ID: Ubuntu
  • Description: Ubuntu 22.04.5 LTS
  • Release: 22.04
  • Codename: jammy

Note: On this system, /etc/resolv.conf is a symbolic link to /run/systemd/resolve/stub-resolv.conf.


Features

  • Tests multiple well-known DNS servers (Cloudflare, Google, Quad9, OpenDNS, AdGuard, ControlD)
  • Measures query time to resolve a specified domain (default: example.com)
  • Handles no-response cases gracefully by marking them as NO RESP
  • Outputs two clean, ASCII-aligned tables:
    • Original unsorted results
    • Results sorted from fastest to slowest
  • Fully ASCII-safe with dynamic column width adjustment

DNS Servers Tested

  • Cloudflare (1.1.1.1)
  • Google Primary (8.8.8.8)
  • Google Backup (8.8.4.4)
  • Quad9 (9.9.9.9)
  • OpenDNS Primary (208.67.222.222)
  • OpenDNS Backup (208.67.220.220)
  • AdGuard Primary (94.140.14.14)
  • AdGuard Backup (94.140.15.15)
  • ControlD Primary (76.76.2.0)
  • ControlD Backup (76.76.10.0)

Usage

./dns-speed-test.sh [domain]
  • domain — Optional. The domain to resolve. Defaults to example.com if omitted.

Download Script

You can download the latest version of the DNS Speed Test script from GitHub:

Download dns-speed-test.sh


Example Output

+-----------+-------------+--------+
| Name      | IP          |  Time  |
+-----------+-------------+--------+
| Cloudflare| 1.1.1.1     |    12ms|
| Google    | 8.8.8.8     |    14ms|
| Quad9     | 9.9.9.9     | NO RESP|
+-----------+-------------+--------+

Sorted (from fastest to slowest):
+-----------+-------------+--------+
| Name      | IP          |  Time  |
+-----------+-------------+--------+
| Cloudflare| 1.1.1.1     |    12ms|
| Google    | 8.8.8.8     |    14ms|
| Quad9     | 9.9.9.9     | NO RESP|
+-----------+-------------+--------+

How It Works

  • Uses dig to query each DNS server for the provided domain.
  • Extracts the query time from the dig output.
  • If no response is received within the timeout, marks it as NO RESP with a high sort value to appear last.
  • Prints two tables:
    1. The original order of DNS servers tested
    2. Sorted results by ascending query time

Dependencies

  • bash
  • dig (from bind-utils or dnsutils package)

License

MIT License


@michele-tn
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment