nslookup command

nslookup (name server lookup) is a tool used to perform DNS lookups in Linux. It is used to display DNS details, such as the IP address of a particular computer, the MX records for a domain or the NS servers of a domain.

nslookup can operate in two modes: interactive and non-interactive. The interactive mode allows you to query name servers for information about various hosts and domains or to print a list of hosts in a domain. The non-interactive mode allows you to print just the name and requested information for a host or domain.

The interactive mode

The interactive mode is entered by typing the nslookup command without any arguments:

linux nslookup interactive mode

To find the IP address of a host, simply type the hostname:

linux nslookup hostname

To perform a reverse DNS lookup, enter the IP address of a host:

linux nslookup ip address

To display MX records (the mail servers responsible for accepting email messages on behalf of a recipient’s domain), set the DNS query type to MX:

linux nslookup mx

To display NS records, set the DNS query type to NS:

linux nslookup ns

The non-interactive mode

The non-interactive mode is invoked by typing the nslookup command, followed by the name or the IP address of the host to be looked up.

For example, to display the IP address of a hostname, use the following command:

linux nslookup command hostname

To do a reverse DNS lookup, use the following command:

linux nslookup reverse dns lookup

To display the MX records, use the -query=mx option:

linux nslookup command mx

To display the NS records, use the -query=ns option:

linux nslookup command ns

To display the SOA record (information about the domain), use the -query=soa option:

linux nslookup command soa

To display all the available DNS records, use the -query=any option:

linux nslookup command any

The nslookup program is officially deprecated, meaning that it’s no longer being maintained. You should use host or dig instead.

 

Geek University recommends the following video course to get you started with Linux.

Geek University 2022