How To Use nslookup Command in Linux

In this guide, we want to teach you How to Use or Work with the nslookup Command in Linux.

Name server lookup (nslookup) is a command-line tool that lets you find the internet protocol (IP) address or domain name system (DNS) record of a specific hostname. This command also allows reverse DNS lookup by inputting the IP addresses of the corresponding domains.

The nslookup tool is useful for DNS-related tasks, such as server testing or Linux troubleshooting issues. 

Steps To Use nslookup Command in Linux

To complete this guide, you must log in to your Linux server and follow the steps below.

Install nslookup in Linux

nslookup comes preinstalled on all major operating systems. If you need to install it again on a Linux distro, use the following commands:

On Ubuntu / Debian:

sudo apt install dnsutils

On CentOS, Fedora, and Red Hat, nslookup is part of the bind-utils package. Install it by running the command below:

sudo dnf install bind-utils

nslookup Modes

Nslookup can be used in interactive and non-interactive modes.

Interactive Mode:

To initiate the nslookup interactive mode, type the command name only:

nslookup

The prompt that appears lets you issue multiple server queries as shown below.

For example, you can type a domain name and receive information about it.

> www.google.com
Output
Server:         1.1.1.1
Address:        1.1.1.1#53

Non-authoritative answer:
Name:   www.google.com
Address: 142.251.140.36
Name:   www.google.com
Address: 2a00:1450:4017:814::2004

In interactive mode, you can specify an option in a separate line before the query. To do this, you can use the following syntax:

set [option]

For example, to get the name servers from google, you can type:

> set type=ns
> google.com

Output
Server:         1.1.1.1
Address:        1.1.1.1#53

Non-authoritative answer:
google.com      nameserver = ns3.google.com.
google.com      nameserver = ns4.google.com.
google.com      nameserver = ns1.google.com.
google.com      nameserver = ns2.google.com.

To exit the nslookup interactive mode in Linux, type the following command:

> exit

non-interactive Mode:

The non-interactive mode lets you use the nslookup command to issue single queries. The syntax for the non-interactive mode is:

nslookup [options] [domain-name]

The command and the query are written in the same line. For example:

nslookup www.google.com
Output
Server:     1.1.1.1
Address:        1.1.1.1#53

Non-authoritative answer:
Name:   www.google.com
Address: 172.217.17.100
Name:   www.google.com
Address: 2a00:1450:4017:814::2004

nslookup Options

At this point, we provide a list of the most common useful nslookup command options in Linux:

nslookup Option	Description
-domain=[domain-name]	Change the default DNS name.
-debug	Show debugging information.
-port=[port-number]	Specify the port for queries. The default port number is 53.
-timeout=[seconds]	Specify the time allowed for the server to respond.
-type=a	View information about the DNS A address records.
-type=any	View all available records.
-type=hinfo	View hardware-related information about the host.
-type=mx	View Mail Exchange server information.
-type=ns	View Name Server records.
-type=ptr	View Pointer records. Used in reverse DNS lookups.
-type=soa	View Start of Authority records.

How To Work with nslookup in Linux

To show the use of the nslookup command in Linux we are going to use it to:

  • Find the IP address of a host.
  • Find the domain name of an IP address.
  • Find mail servers for a domain.

These are probably the most common usage scenarios.

Find the Host IP Address

To find an IP address of a host, you can use the following syntax in a non-interactive mode:

nslookup domain-name

In interactive mode, you can use the following syntax:

nslookup
> domain-name

Find the domain name of an IP address

You can use the nslookup command to find the domain name of an IP address in Linux. In a non-interactive mode, you can use the following syntax:

nslookup IP-address

In interactive mode, you can use the following syntax:

nslookup 
> IP-address

Find mail servers for a domain

To find the mail servers for a domain name, you can use the following syntax in a non-interactive mode:

nslookup  -querytype=mx  domain name

In interactive mode, you can use the following syntax:

nslookup
> set type=mx
> domain-name

These are the basic and most common useful nslookup commands.

Conclusion

At this point, you have learned to Use or Work with the nslookup Command in Linux.

The main use of nslookup is for troubleshooting DNS-related problems.

Hope you enjoy it.

You may be like these articles:

Unable To Connect to cqlsh Cassandra

XAMPP Unable To Determine IP Address of hostname

Fix phpMyAdmin SSL Error Connection

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular