How To Troubleshooting DNS on Linux

At some point, DNS will make its way to you. For the older generation System Administrator, there is a famous quote “It is always DNS”. DNS propagation in some countries might take 1×24 hour to propagated, the ISP had some weird caching technique. To troubleshooting DNS problem on Linux use dig or nslookup. TTL (time to live) is important when setting DNS record, the lower TTL goes, the public DNS will more often query the records for changes.

6 of the most used DNS records
1. A record, used to store an IP address.
2. AAAA, IPv6 version of A record
3. CNAME, canonical name or alias
4. MX, mail exchange record
5. NS, name server record
6. TXT, text record, usually used to verify ownership of the domain for some services, such as Google Webmaster, Bing Webmaster, Docusign.

Check DNS Records

On following tutorial both dig and nslookup will be used. It handy to know both tools because some distro include one or the other on default instalation.

A Record

To check the A record using dig

dig a

the result similiar to just dig, it’s defaulted to check A record.
dig check dns record

to check A record using nslookup


MX Record

MX record used to serve mail server

dig mx
# or
nslookup <enter>
set type=mx <enter> <enter>

nslookup domain mx

nslookup command on Linux compatible with Windows.

Automated Script

A simple script to check multiple public DNS server

for SERVER in; do
  echo "$SERVER"
  dig mx @$SERVER +short
  echo "--------------------------"

replace with yours, and mx with any record.

Let’s test the script to check A record of domain

> for SERVER in; do
>   echo "$SERVER"
>   dig a @$SERVER +short
>   echo "--------------------------"
> done

dns script output

Leave a Comment