10
votes

I am working on switching the nameserves of my domain to a new DNS service. What is the best tool to compare the new settings with the existing DNS setup.

I have tried to use dig with and without @nameserver to allow me to make sure that the DNS records match between the old and the new provider.

No success so far.

Any ideas ?

3
What do you mean by "No success so far"? dig is about as useful a tool as you're going to find for this job. What exactly didn't work?Celada

3 Answers

20
votes

I answer that old question, I was confronted with this problem and I solved it this way:

For a single domain:

diff <(sort -u <(dig +nottlid +noall +answer @ns.myfirstserver.com example.com ANY) ) <(sort -u <(dig +nottlid +noall +answer @ns.mysecondserver.com example.com ANY) )

For multiple domains or subdomains:

  • Create a text file with 1 domain by line (by example: alldomains.txt)

The command line:

diff <(sort -u <(for host in $(cat alldomains.txt); do dig +nottlid +noall +answer @ns.myfirstserver.com $host ANY; done) ) <(sort -u <(for host in $(cat alldomains.txt); do dig +nottlid +noall +answer @ns.mysecondserver.com $host ANY; done) )

Comments:

  • diff: compare files line by line
  • sort: sort lines of text files
  • -u: make sure that there is only unique line
  • dig: DNS lookup utility
  • +nottlid: do not display the TTL when printing the record
  • +noall: clear all display flags
  • answer: display the authority section of a reply.
  • @ns.server.com: name or IP address of the name server to query
  • ANY: indicates what type of query is required (ANY, A, MX, SIG, etc.)

You can redirect to a file by adding > myresult.txt at end.

I hope this can help someone.

1
votes

And yey! In inspiration from code-source's answer I created this to check from a known zone file. Since ANY query does not output the full zone.

Input is zonefile in bind format with the first field mandatory and full !! No support for empty first field or shortened yet!

zone=test.txt; ns1=ns1.test.com; ns2=ns2.test.com; \
zcl=$(basename ${zone} .txt)_cl.txt; zl1=$(basename ${zcl} .txt)_${ns1}.log; zl2=$(basename ${zcl} .txt)_${ns2}.log; \
echo "Diffing the stuff in $zcl (from $zone) for $ns1 <-> $ns2" >&2 ;echo " loggings to $zl1, $zl2" >&2 ; \
cat $zone | awk 'BEGIN {IFS=" "} $1 !~ /^;|^[[:space:]]+|^$/ {t=$4; if (!match($2,/[[:digit:]]/)) t=$3; n=$1; print n " " t }' | sort -u > $zcl ; \
diff <(sort -u <(while read host type; do echo "Q $host $type" >&2; dig +nottlid +noall +answer @$ns1 $host $type; done < $zcl) | tee $zl1 ) \
     <(sort -u <(while read host type; do dig +nottlid +noall +answer @$ns2 $host $type; done < $zcl) | tee $zl2 ) && echo "OK"
1
votes

This script was made to compare two zone files during a migration.

It uses colour coding and a final status output to indicate what records are different

SOA and NS records will be different during a migration - just note the differences

ANY record will probably be different too as it includes above types in it.

A MX and TXT records should be the same , if they exist - difference here means a problem !

See Example Screenshot

Source: https://github.com/geek4unix/compare-zones/