Compare DNS on two different nameservers
Asked Answered
U

4

14

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 ?

Ulceration answered 13/6, 2012 at 23:28 Comment(1)
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?Adenosine
F
28

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.

Fairleigh answered 16/3, 2015 at 14:55 Comment(4)
If one of the nameservers allows zone transfers to you IP you can compare all hosts (excluding ones that only the other nameserver knows about) with: diff <(sort -u <(dig +nottlid +noall +answer -t AXFR @ns.myfirstserver.com example.com) ) <(sort -u <(for host in $(dig +nottlid +noall +answer -t AXFR @ns.myfirstserver.com example.com | cut -f 1 | sort -u); do dig +nottlid +noall +answer @ns.mysecondserver.com $host ANY; done) )Amphibian
If the zone contains delegations to other nameservers i also need to add +authority to the dig command.Amphibian
I've put it into a script: gist.github.com/maiers/3a9dd183dd5e6c434a85694c1fb2a57aIngest
Really nice, but be aware that ANY is not supported (anymore) by all DNS servers. I know of Cloudflare specifically: blog.cloudflare.com/what-happened-next-the-deprecation-of-anyLunneta
T
2

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/

Thinnish answered 14/5, 2021 at 22:17 Comment(0)
K
1

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"
Karolekarolina answered 26/6, 2019 at 8:31 Comment(0)
F
0

Here's my one-liner that just shows the A records in two columns:

dig +short @8.8.8.8 pjbrunet.com|(b=$(cat);dig +short @8.8.8.8 google.com <<<"$b"|diff -y <(echo "$b") -)

Looks like:

1.2.3.4                           | 142.251.45.78

If you're moving your blog/website to another host, usually you're looking at the A record. Looks like dig +short just returns the A record, which is what I look at when waiting for propagation.

You probably want to change 8.8.8.8 to something else, assuming you're comparing two different DNS results. Here's a list of global DNS servers.

For normal diff output, just remove -y

Fenland answered 2/5, 2023 at 4:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.