The nslookup utility can be installed and used on a Linux system to find out information about the DNS records for a domain or IP address. It's particularly handy when troubleshooting DNS issues. A popular tool that also comes installed with nslookup is dig, which is similar but uses different resolvers. It's a good alternative to nslookup, but nslookup is typically easier to use.

In this tutorial, we'll guide you through the installation of nslookup on major Linux distributions and show various command line examples that you can use on your own system when you need to obtain DNS information.

In this tutorial you will learn:
  • How to install nslookup on major Linux distros
  • Nslookup command line examples
nslookup command on Linux
nslookup command on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software nslookup
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Install nslookup

There's a good chance that nslookup is already installed on your system and ready to use. But, if not, just use the appropriate command below to install it.


SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


To install nslookup on Ubuntu, Debian, Linux Mint, and any other Debian based distribution:

$ sudo apt install dnsutils

To install nslookup on CentOS, Fedora, Red Hat, and any other Red Hat based distribution:

$ sudo dnf install bind-utils

To install nslookup on Manjaro, Arch Linux, and any other Arch Linux based distribution:

$ sudo pacman -S dnsutils

Nslookup command line examples

Now that nslookup is installed, try some of the following commands to get a feel for how it works.

To see basic information about a domain's A record, simply specify the domain name as an argument. The output may contain multiple IP addresses, depending on the queried server's configuration.

$ nslookup redhat.com
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	redhat.com
Address: 209.132.183.105


You can also look up the reverse DNS record by specifying the IP address and seeing which domain name it points to.

$ nslookup 209.132.183.105
105.183.132.209.in-addr.arpa	name = redirect.redhat.com.

To see the mail record (MX) for a domain, use the -query=MX option. This record controls where mail sent to the domain (in this case, @redhat.com) is sent to.

$ nslookup -query=mx redhat.com
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
redhat.com	mail exchanger = 10 us-smtp-inbound-2.mimecast.com.
redhat.com	mail exchanger = 10 us-smtp-inbound-1.mimecast.com.

Use the -query=ns option to see a list of DNS servers for the domain.

$ nslookup -type=ns redhat.com
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
redhat.com	nameserver = a10-65.akam.net.
redhat.com	nameserver = a9-65.akam.net.
redhat.com	nameserver = a13-66.akam.net.
redhat.com	nameserver = a28-64.akam.net.
redhat.com	nameserver = a1-68.akam.net.
redhat.com	nameserver = a16-67.akam.net.

These are some of the main options for nslookup, although there are more query types available and further options. Check out the man page for more details, and maybe give the dig command a try as well.

$ man nslookup
AND
$ man dig

Conclusion

In this guide, we learned how to install the nslookup utility on major Linux distributions. We also saw several example commands for querying DNS information from a domain name and IP address. The nslookup command is super handy when you need to see a concise list of DNS information.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions