Comparing DNS records on two nameservers

We've all been there: you've just manually copied 30+ DNS records from one server to another and you're about to press the metaphorical red button by updating the domain's nameservers. If only there was a way to make sure you've copied everything correctly.

Well, here it is! Using a clever combination of using dig to fetch DNS records, sort to make sure they're all sorted and diff to take pick up any differences, we can compare the old nameserver's DNS records to the new server's DNS records. The full command looks like this:

Compare DNS records on two nameservers

diff <(sort -u <(dig +nocmd +noall +answer +nottlid @ns1.old-nameserver.com example.com ANY)) <(sort -u <(dig +nocmd +noall +answer +nottlid @ns1.new-nameserver.com example.com ANY))

Wondering what's going on there? Take a quick look at this explainshell.com. The command is also using process substitution to write the output of dig and sort to a temporary file to have it work well with diff.