Automating DNS Propagation Checks with dig on Linux

I do a lot of hosting migrations on Codeable to help WordPress site owners make their site faster. For anybody who has migrated hosts before you know the major bottleneck is DNS and its slow propagation.

I usually check DNS records with DNS Checker and it works very well but it requires manual labor. I prefer to automate wherever possible so I decided to make this little script to send me a Pushbullet notification when the name servers have updated. It can be adapted to send an email instead and for other DNS record types.

Automating DNS Propagation Checks with dig on Linux

On Debian and Ubuntu systems you need the dnsutils package

sudo apt-get update
sudo apt-get install dnsutils -y

On CentOS it is called bind-utils

yum install bind-utils

Now we are ready to use the dig command.

Quick DNS Propagation Checks

The main records I usually have to check for a host migration are

  • NS records – name servers
  • A records
  • CNAME records
  • TXT records

Name Servers

To get your name servers

dig NS +short

Notice the . at the end of the domain name. This is actually always present but hidden in browsers.

The . stands for root (start here) since DNS is processed from right to left.

A Records

To get your domain’s A records

dig A +short

Output, notice there are 2 because I use Cloudflare

CNAME Records

Checking for CNAMEs remember to add the prefix to your domain, here

dig CNAME +short

Output, notice again the . at the end

TXT Records

To get TXT records – useful if you are adding email verification for Mailgun, Sendgrid or Gsuite

dig TXT +short


"v=spf1 ~all"

Checking DKIM TXT records for signing email so it doesn’t go to spam folders

dig TXT +short

Those are the most common record types I check, now let’s automate it.

Automation Script Example

Here is how I am checking if name servers have been updated, it can be adjusted for other DNS record types.

Create a scripts folder

mkdir ~/scripts

Create a new empty script

nano ~/scripts/

Paste the script below and adjust the follow variables

  • DOMAIN is your domain name
  • PUSHBULLET is your Pushbullet API Key
  • NSUPDATED[0] is the primary name server
  • NSUPDATED[1] is the secondary name server
#!/usr/bin/env bash
# Purpose: DNS Propagation checker
# Source:

# make sure DNS utilities are installed
if hash dig 2>/dev/null; then
    echo "DNS utilities not installed"

# domain to check

# pushbullet API key

# array of desired nameservers in order, remember . at the end

# make the DNS NS check
WPBULLETNS=($(dig $DOMAIN NS +short))

# variables for comparison checks

# check if nameservers are equal and send pushbullet notification
    curl --header "Access-Token: $PUSHBULLET" \
     --header 'Content-Type: application/json' \
     --data-binary '{"body":"DNS NS Updated","title":"'"$DOMAIN"'","type":"note"}' \
     --request POST \

Ctrl+X, Y and Enter to Save and Exit

Make the script executable

sudo chmod +x ~/scripts/

We are going to schedule the script in a cronjob

crontab -e

This will run the script every 5 minutes, change 5 to another value if you would like to use a different interval.

*/5 * * * * /bin/bash /home/wpbullet/scripts/

You should see a pushbullet notification when the name servers have updated 🙂


Check DNS Records with dig
Install dig on CentOS 6
DNS Propagation Checker
Check 2 Arrays are Equal bash
Pushbullet API Docs