
Use apt-get or yum to install DIG (and other DNS utilities).
[root@server1 ~]# yum install bind-utils
The DIG command followed by a domain name will display information about the domain name, such as the A record (IPv4 address) of the domain. The QUESTION SECTION is simply the lookup you are performing, and the ANSWER SECTION is the answer to the question. The AUTHORITY SECTION lists the name servers that are being used.
[root@server1 ~]# dig www.example.com
. . .
;; QUESTION SECTION:
;www.example.com IN A
;; ANSWER SECTION:
www.example.com. 875 IN A 93.184.216.34
;; AUTHORITY SECTION:
example.com. 6728 IN NS a.iana-servers.net.
example.com. 6728 IN NS b.iana-servers.net.
. . .
Reverse lookup
The -x option can be used to do a reverse lookup, to resolve an IP address to a hostname.
[root@server1 ~]# dig -x 12.34.56.78
. . .
;; ANSWER SECTION:
87.65.43.21.in-addr.arpa. 86400 IN PTR cpe-87-65-43-21.example.com.
. . .
Answer section
Typically, only the ANSWER SECTION is needed. The following options can be appended to only display the ANSWER SECTION.
[root@server1 ~]# dig www.example.com +nocomments +noquestion +noauthority +noadditional +nostats
. . .
www.example.com. 875 IN A 93.184.216.34
The same can be accomplished using the following options.
[root@server1 ~]# dig www.example.com +noall +answer
. . .
www.example.com. 875 IN A 93.184.216.34
IP address only
The +short option can be used to only display the IP addresss from the ANSWER SECTION.
[root@server1 ~]# dig www.example.com +short
93.184.216.34
MX records
The MX or -t MX option can be used to add the mail records to the output.
[root@server1 ~]# dig www.example.com MX
. . .
;; ANSWER SECTION:
www.example.com. 875 IN A 93.184.216.34
example.com 900 IN MX 5 mx1.example.com.
example.com 900 IN MX 10 mx2.example.com.
. . .
NS records
The NS or -t NS option can be used to add the name servers to the output.
[root@server1 ~]# dig www.example.com NS
. . .
;; ANSWER SECTION:
www.example.com. 875 IN A 93.184.216.34
example.com 900 IN NS ns1.domaincontrol.com.
example.com 900 IN NS ns1.domaincontrol.com.
. . .
SOA
The SOA or -t SOA option can be used to display the Start of Authority.
[root@server1 ~]# dig www.example.com SOA
. . .
;; AUTHORITY SECTION:
example.com. 60 IN SOA sns.dns.icann.org noc.dns.icann.org 201611078 7200 3600 1209600 3600
. . .
Use a different nameserver
Instead of using the DNS server in /etc/resolv.conf, the @ character followed by the IP address of the nameserver you would like to use can be used to use an alternate nameserver. In this example, Google's 8.8.8.8 nameserver is used.
[root@server1 ~]# dig @8.8.8.8 www.example.com
. . .
;; ANSWER SECTION:
www.example.com. 875 IN A 93.184.216.34
. . .
Use a preferred interface
The machine may have two or more interfaces. For example, let's say eth0 has IP address 192.168.0.100, and eth1 has IP address 10.0.0.100. The -b option can be used to select the interface to use.
[root@server1 ~]# dig -b 192.168.0.100 www.example.com
. . .
;; QUESTION SECTION:
;www.example.com IN A
;; ANSWER SECTION:
www.example.com. 875 IN A 93.184.216.34
. . .
Did you find this article helpful?
If so, consider buying me a coffee over at