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.
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.
By adding the @22.214.171.124 we are telling dig to query Google's DNS server (IP Address of 126.96.36.199).
dig @188.8.131.52 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 @184.108.40.206 centoshowtos.org +short
We can resolve the hostname of 220.127.116.11 using the "-x" option. This can be combined with the @18.104.22.168 or whatever DNS server you wish to query.
dig -x 22.214.171.124
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 @126.96.36.199 -x 188.8.131.52 +short
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
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(Comments)
; (1 server found)
;; global options: +cmd
; Transfer failed.