Bootstrap FreeKB - Linux Commands - dig (name server lookup DNS)
Linux Commands - dig (name server lookup DNS)

Updated:   |  Linux Commands articles

On some Linux distributions, the dig (Domain Information Groper) command will not be installed. On a Debian distribution (Debian, Mint, Ubuntu), the apt-get command can be used to install the bind-utils package, which includes the dig command. On a Red Hat distrubtion (CentOS, Fedora, Red Hat), the dnf or yum command can be used.

Use apt-get or yum to install bind-utils, which contains the nslookup utility.

dnf install bind-utils

 

The dig command can be used to determine if one of the DNS name servers being used is able to resolve a hostname to an IP address. Something like this should be returned. In this example, the name server at 192.168.0.16 was able to resolve www.example.com to 93.184.216.34.

~]# dig www.example.com

; <<>> DiG 9.16.11-RedHat-9.16.11-5.fc34 <<>> www.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52129
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 8683588479247e62010000006163f0bdd0acdc39f0000fab (good)
;; QUESTION SECTION:
;www.example.com.               IN      A

;; ANSWER SECTION:
www.example.com.        19734   IN      A       93.184.216.34

;; Query time: 84 msec
;; SERVER: 192.168.0.16#53(192.168.0.16)
;; WHEN: Mon Oct 11 03:07:25 CDT 2021
;; MSG SIZE  rcvd: 88

 

On the other hand, if the name servers are unable to resolve the hostname to an IP address, something like this should be returned.

~]# dig www.bogus.com

; <<>> DiG 9.16.11-RedHat-9.16.11-5.fc34 <<>> www.bogus.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 42936
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 7db3d264e99c4f8b010000006163f106264ecfb9cdf065bb (good)
;; QUESTION SECTION:
;www.bogus.com.                 IN      A

;; AUTHORITY SECTION:
bogus.com.              1800    IN      SOA     rip.psg.com. hostmaster.psg.com. 1633937074 345600 7200 2592000 3600

;; Query time: 211 msec
;; SERVER: 192.168.0.16#53(192.168.0.16)
;; WHEN: Mon Oct 11 03:08:38 CDT 2021
;; MSG SIZE  rcvd: 128

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter eeeda6 in the box below so that we can be sure you are a human.