Skip to content

Instantly share code, notes, and snippets.

@tommilligan
Created July 18, 2025 16:32
Show Gist options
  • Select an option

  • Save tommilligan/8b3741ac0a334e5a0f9d40b91ce987a1 to your computer and use it in GitHub Desktop.

Select an option

Save tommilligan/8b3741ac0a334e5a0f9d40b91ce987a1 to your computer and use it in GitHub Desktop.
Verify that two DNS servers behave the same for a list of records, before changing authoritative DNS servers.
#!/bin/bash
# Takes:
# - An input file with a list of hostnames to resolve
# - An old DNS server address
# - A new DNS server address
#
# Output will be a diff between the behaviour of the two DNS servers for the domains given.
set -euo pipefail
# Contains a hostname per line
input_file="$1"
SERVER_A="$2"
SERVER_B="$3"
RED='\033[0;31m'
GREEN='\033[0;32m'
CLEAR='\033[0m'
eprintln() {
local message="$1"
>&2 echo -e "$message"
}
eprintln "Comparing DNS servers ${RED}'$SERVER_A'${CLEAR} and ${GREEN}'$SERVER_B'${CLEAR}"
while read -r line; do
eprintln "> $line"
diff --color -u <(dig $line "@${SERVER_A}" +short | sort) <(dig $line "@${SERVER_B}" +short | sort)
done < "$input_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment