Resolve DNS with dig

The dig utility is extemely handy and important to be familiar with when diagnosing issues or simply confirming that domain name service resolution is working properly.  It is used to query a DNS server and resolve an IP from a FQDN, or perform a reverse lookup to obtain the hostname of an IP address.

Resolve centoshowtos.org

Simply type the FQDN you wish to resolve after dig to resolve it's IP and get other information. With no other arguments passed, dig will default to resolving from your system's configured DNS servers in /etc/resolv.conf.

 dig centoshowtos.org

Resolve centoshowtos.org from Google's DNS Server

By adding the @ we are telling dig to query Google's DNS server (IP Address of

 dig @ centoshowtos.org

The dig command on its own will give you quite a bit of verbosity. If you are looking for just the IP address, we just add +short at the end of the command.

 dig @ centoshowtos.org +short

Resolve hostname of Google's DNS Server

We can resolve the hostname of using the "-x" option. This can be combined with the @ or whatever DNS server you wish to query.

 dig -x

The -x flag for reverse lookups can be combined with the options demonstrated above. We can add @ and the IP or hostname of the DNS server you wish to query, as well as +short at the end to only return the FQDN from the reverse lookup.

 dig @ -x +short

Resolve GMail's MX Record

You can add MX as a record type to obtain the mail exchange record IP for a domain name.

dig gmail.com MX +noall +answer

Again we can add +short to return the IP only.

dig gmail.com MX +short

Dump a Zone File

If you want to dump an entire zone file, you would use axfr.

dig @nameserver.hostname.or.ip mydomainexample.com axfr

This should print a zonefile to the screen. You can obviously redirect this output to a zone file. If you get a "Transfer failed." in the output and no zone file, you need to configure your nameserver to "allow-transfer". For bind, you can specify this in the named.conf.

; <<>> DiG 9.8.3-P1 <<>> @nameserver.hostname.or.ip mydomainexample.com axfr
; (1 server found)
;; global options: +cmd
; Transfer failed.