How to Install and Use dig and nslookup Commands in Linux

In this article, you will learn how to install the dig command and nslookup command on Linux. These commands are used for network troubleshooting and gathering information about domain names.

Dig, short for Domain Information Gopher, is a DNS lookup utility used for probing DNS servers and troubleshooting problems associated with DNS servers. Due to its ease of use, system administrators rely on the tool to troubleshoot DNS issues.

Nslookup is used for handling DNS lookups and displays crucial information such as MX records, and the IP address associated with a domain name.

Newer Linux system ship both dig and nslookup utilities by default. However, older Linux systems may not. The two come bundled inside the bind-utils package.

Let’s see how we can install DNS troubleshooting utilities in Linux.

Installing dig & nslookup in CentOS/RHEL

On Red Hat Linux /CentOS, install dig and nslookup using the dnf command.

# dnf install bind-utils
Install Bind-Utils in CentOS
Install Bind-Utils in CentOS

Upon successful installation, verify the version using the command below.

# dig -v
Check Dig Command Version
Check Dig Command Version

Installing dig & nslookup on Debian / Ubuntu

On Debian and any of its derivatives including Debian, the installation is done using the apt command.

# apt install dnsutils
Install DNS Utils in Debian and Ubuntu
Install DNS Utils in Debian and Ubuntu

Again, to verify the installation, run the command.

# dig -v
Check dig Version in Debian and Ubuntu
Check dig Version in Debian and Ubuntu

Installing dig & nslookup on ArchLinux

For ArchLinux, the command for installing dig and nslookup will be.

# pacman -Sy dnsutils
Install dns-utils Arch Linux
Install dns-utils Arch Linux

To check the version of dig installed, run.

# dig -v
Check dig Version in Arch Linux
Check dig Version in Arch Linux

Using the dig command

dig command can be used to query a domain name and retrieve information as shown:

# dig fossmint.com

The command displays a host of information such as the version of the dig command utility, the DNS server, and its corresponding IP address.

Sample Output
; <<>> DiG 9.11.3-1ubuntu1.9-Ubuntu <<>> fossmint.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58049
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;fossmint.com.			IN	A

;; ANSWER SECTION:
fossmint.com.		300	IN	A	104.27.179.254
fossmint.com.		300	IN	A	104.27.171.254

;; Query time: 6 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Nov 15 12:33:55 IST 2019
;; MSG SIZE  rcvd: 73

To get more specific and display only the IP of the domain name append the +short argument as shown:

# dig fossmint.com +short

104.17.179.254
104.17.171.254

To check the MX record of the domain name run.

# dig fossmint.com MX +short

50 mx3.zoho.com.
20 mx2.zoho.com.
10 mx.zoho.com.

Using the nslookup Command

To retrieve information about a domain name using the nslookup utility, use the following command.

# nslookup fossmint.com
Sample Output
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	fossmint.com
Address: 104.27.179.254
Name:	fossmint.com
Address: 104.27.171.254
Name:	fossmint.com
Address: 2606:4700:30::681b:b0fe
Name:	fossmint.com
Address: 2606:4700:30::681b:b1fe
Conclusion

In this article, you learned how to install dig and nslookup command utilities in different Linux distributions and also the basic usage of the commands. We do hope that you can now comfortably install the utilities when confronted with a system without them.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 Comment

Leave a Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.