How to use dig and nslookup in CentOS 7

Posted on

Specific tool which is important in an operating system where in this context, it is Linux operating system, it is dig and nslookup. But in order to have a tool mentioned above, dig and nslookup, there is a step which is needed to be taken so that it can be available to be executed from the Linux operating system associated. The Linux operating system mentioned in the context of this article, it is CentOS 7.

CentOS 7 has its own software package manager utility for managing the installation of application, program, package or any other tools or utilities needed to perform specific task or function. Derived from Redhat Linux operating system family, CentOS uses yum utility as its software package manager.

Speaking of installing tools or utilities which is needed to execute or to perform specific task or function, dig and nslookup are tools or utilities utilized to resolve name server.

Just type the following command calling ‘yum’ as the software package manager under CentOS to install the tool or utility represented by a package named ‘bind-utils’ :

[root@hostname ~]# yum -y install bind-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package bind-utils.x86_64 32:9.9.4-38.el7_3.3 will be installed
--> Processing Dependency: bind-libs = 32:9.9.4-38.el7_3.3 for package: 32:bind-utils-9.9.4-38.el7_3.3.x86_64
--> Processing Dependency: liblwres.so.90()(64bit) for package: 32:bind-utils-9.9.4-38.el7_3.3.x86_64
--> Processing Dependency: libisccfg.so.90()(64bit) for package: 32:bind-utils-9.9.4-38.el7_3.3.x86_64
--> Processing Dependency: libisccc.so.90()(64bit) for package: 32:bind-utils-9.9.4-38.el7_3.3.x86_64
--> Processing Dependency: libisc.so.95()(64bit) for package: 32:bind-utils-9.9.4-38.el7_3.3.x86_64
--> Processing Dependency: libdns.so.100()(64bit) for package: 32:bind-utils-9.9.4-38.el7_3.3.x86_64
--> Processing Dependency: libbind9.so.90()(64bit) for package: 32:bind-utils-9.9.4-38.el7_3.3.x86_64
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: 32:bind-utils-9.9.4-38.el7_3.3.x86_64
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-11.el7 will be installed
---> Package bind-libs.x86_64 32:9.9.4-38.el7_3.3 will be installed
--> Processing Dependency: bind-license = 32:9.9.4-38.el7_3.3 for package: 32:bind-libs-9.9.4-38.el7_3.3.x86_64
--> Running transaction check
---> Package bind-license.noarch 32:9.9.4-18.el7_1.5 will be updated
--> Processing Dependency: bind-license = 32:9.9.4-18.el7_1.5 for package: 32:bind-libs-lite-9.9.4-18.el7_1.5.x86_64
---> Package bind-license.noarch 32:9.9.4-38.el7_3.3 will be an update
--> Running transaction check
---> Package bind-libs-lite.x86_64 32:9.9.4-18.el7_1.5 will be updated
---> Package bind-libs-lite.x86_64 32:9.9.4-38.el7_3.3 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================================
 Package                                                  Arch                                             Version                                                        Repository                                         Size
==================================================================================================================================================================================================================================
Installing:
 bind-utils                                               x86_64                                           32:9.9.4-38.el7_3.3                                            updates                                           202 k
Installing for dependencies:
 GeoIP                                                    x86_64                                           1.5.0-11.el7                                                   base                                              1.1 M
 bind-libs                                                x86_64                                           32:9.9.4-38.el7_3.3                                            updates                                           1.0 M
Updating for dependencies:
 bind-libs-lite                                           x86_64                                           32:9.9.4-38.el7_3.3                                            updates                                           730 k
 bind-license                                             noarch                                           32:9.9.4-38.el7_3.3                                            updates                                            83 k

Transaction Summary
==================================================================================================================================================================================================================================
Install  1 Package  (+2 Dependent packages)
Upgrade             ( 2 Dependent packages)

Total download size: 3.0 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): GeoIP-1.5.0-11.el7.x86_64.rpm                                                                                                                                                                       | 1.1 MB  00:00:00     
(2/5): bind-libs-9.9.4-38.el7_3.3.x86_64.rpm                                                                                                                                                               | 1.0 MB  00:00:00     
(3/5): bind-libs-lite-9.9.4-38.el7_3.3.x86_64.rpm                                                                                                                                                          | 730 kB  00:00:00     
(4/5): bind-license-9.9.4-38.el7_3.3.noarch.rpm                                                                                                                                                            |  83 kB  00:00:00     
(5/5): bind-utils-9.9.4-38.el7_3.3.x86_64.rpm                                                                                                                                                              | 202 kB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                             8.1 MB/s | 3.0 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : GeoIP-1.5.0-11.el7.x86_64                                                                                                                                                                                      1/7 
  Updating   : 32:bind-license-9.9.4-38.el7_3.3.noarch                                                                                                                                                                        2/7 
  Installing : 32:bind-libs-9.9.4-38.el7_3.3.x86_64                                                                                                                                                                           3/7 
  Installing : 32:bind-utils-9.9.4-38.el7_3.3.x86_64                                                                                                                                                                          4/7 
  Updating   : 32:bind-libs-lite-9.9.4-38.el7_3.3.x86_64                                                                                                                                                                      5/7 
  Cleanup    : 32:bind-libs-lite-9.9.4-18.el7_1.5.x86_64                                                                                                                                                                      6/7 
  Cleanup    : 32:bind-license-9.9.4-18.el7_1.5.noarch                                                                                                                                                                        7/7 
  Verifying  : 32:bind-utils-9.9.4-38.el7_3.3.x86_64                                                                                                                                                                          1/7 
  Verifying  : GeoIP-1.5.0-11.el7.x86_64                                                                                                                                                                                      2/7 
  Verifying  : 32:bind-libs-lite-9.9.4-38.el7_3.3.x86_64                                                                                                                                                                      3/7 
  Verifying  : 32:bind-libs-9.9.4-38.el7_3.3.x86_64                                                                                                                                                                           4/7 
  Verifying  : 32:bind-license-9.9.4-38.el7_3.3.noarch                                                                                                                                                                        5/7 
  Verifying  : 32:bind-libs-lite-9.9.4-18.el7_1.5.x86_64                                                                                                                                                                      6/7 
  Verifying  : 32:bind-license-9.9.4-18.el7_1.5.noarch                                                                                                                                                                        7/7 

Installed:
  bind-utils.x86_64 32:9.9.4-38.el7_3.3                                                                                                                                                                                           

Dependency Installed:
  GeoIP.x86_64 0:1.5.0-11.el7                                                                                 bind-libs.x86_64 32:9.9.4-38.el7_3.3                                                                                

Dependency Updated:
  bind-libs-lite.x86_64 32:9.9.4-38.el7_3.3                                                                        bind-license.noarch 32:9.9.4-38.el7_3.3                                                                       

Complete!

After successfully installed dns-utils package, there are several utilities which can be used to resolve name server. Below is the usage of the tool or utility in order to resolve some name server :

1. The ‘dig’ utility. Based on the manual page, it is stated as a DNS lookup utility. Below is the execution of the ‘dig’ command :

[root@hostname ~]# dig

; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3.3 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64566
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 22

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;.                              IN      NS

;; ANSWER SECTION:
.                       66381   IN      NS      i.root-servers.net.
.                       66381   IN      NS      f.root-servers.net.
.                       66381   IN      NS      b.root-servers.net.
.                       66381   IN      NS      h.root-servers.net.
.                       66381   IN      NS      a.root-servers.net.
.                       66381   IN      NS      g.root-servers.net.
.                       66381   IN      NS      e.root-servers.net.
.                       66381   IN      NS      d.root-servers.net.
.                       66381   IN      NS      m.root-servers.net.
.                       66381   IN      NS      k.root-servers.net.
.                       66381   IN      NS      j.root-servers.net.
.                       66381   IN      NS      c.root-servers.net.
.                       66381   IN      NS      l.root-servers.net.

;; ADDITIONAL SECTION:
i.root-servers.net.     68529   IN      A       xxx.xxx.xxx.xxx
i.root-servers.net.     83275   IN      AAAA    xxxx:xxx:xxx:xxx
f.root-servers.net.     69184   IN      A       xxx.xxx.xxx.xxx
b.root-servers.net.     69235   IN      A       xxx.xxx.xxx.xxx
b.root-servers.net.     68618   IN      AAAA    xxxx:xxx:xxx:xxx
h.root-servers.net.     67240   IN      A       xxx.xxx.xxx.xxx
a.root-servers.net.     66254   IN      A       xxx.xxx.xxx.xxx
a.root-servers.net.     67447   IN      AAAA    xxxx:xxx:xxx:xxx
g.root-servers.net.     74051   IN      A       xxx.xxx.xxx.xxx
g.root-servers.net.     64150   IN      AAAA    xxxx:xxx:xxx:xxx
e.root-servers.net.     68529   IN      A       xxx.xxx.xxx.xxx
e.root-servers.net.     68435   IN      AAAA    xxxx:xxx:xxx:xxx
d.root-servers.net.     75016   IN      A       xxx.xxx.xxx.xxx
d.root-servers.net.     83274   IN      AAAA    xxxx:xxx:xxx:xxx
m.root-servers.net.     69127   IN      A       xxx.xxx.xxx.xxx
k.root-servers.net.     68528   IN      A       xxx.xxx.xxx.xxx
j.root-servers.net.     68528   IN      A       xxx.xxx.xxx.xxx
c.root-servers.net.     81887   IN      A       xxx.xxx.xxx.xxx
c.root-servers.net.     68618   IN      AAAA    xxxx:xxx:xxx:xxx
l.root-servers.net.     9984    IN      A       xxx.xxx.xxx.xxx
l.root-servers.net.     81547   IN      AAAA    xxxx:xxx:xxx:xxx

;; Query time: 2 msec
;; SERVER: xxx.xxx.xxx.xxx#xx(xxx.xxx.xxx.xxx)
;; WHEN: Mon Sep 11 17:13:02 2017
;; MSG SIZE  rcvd: 684

[root@hostname ~]# 

This is the execution command ‘dig’ with the additional parameter of a name server as shown below :

[root@hostname ~]# dig my.server.com

; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3.3 <<>> my.server.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4415
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;my.server.com.            IN      A

;; ANSWER SECTION:
my.server.com.     3600    IN      A       xxx.xxx.xxx.xxx

;; Query time: 2 msec
;; SERVER: xxx.xxx.xxx.xxx#53(xxx.xxx.xxx.xxx)
;; WHEN: Mon Sep 11 17:13:39 2017
;; MSG SIZE  rcvd: 63

[root@hostname ~]# 

2. The ‘nslookup” utility, it is represented by a command ‘nslookup’ which is also a command used for name server resolver and based on the manual page it functions to query Internet name servers interactively.

[root@hostname ~]# nslookup
> ^C
[root@hostname ~]# 

This is the execution of the command with the additional parameter in the form of an address which is going to be resolved :

[root@hostname ~]# nslookup www.google.com
Server:         127.0.1.1
Address:        127.0.1.1#53

Non-authoritative answer:
Name:   www.google.com
Address: 74.125.200.99
Name:   www.google.com
Address: 74.125.200.105
Name:   www.google.com
Address: 74.125.200.106
Name:   www.google.com
Address: 74.125.200.104
Name:   www.google.com
Address: 74.125.200.147
Name:   www.google.com
Address: 74.125.200.103

root@hostname:~$

One thought on “How to use dig and nslookup in CentOS 7

Leave a Reply