Skip to content

nslookup command in Linux

The nslookup command in Linux is a powerful tool used for querying Domain Name System (DNS) servers. It allows users to perform various types of DNS queries, such as finding the IP address of a domain, resolving domain names to IP addresses, and troubleshooting network connectivity issues. By using nslookup, system administrators and users can gather valuable information about domain names and their corresponding IP addresses, helping them identify and resolve DNS-related problems efficiently.

nslookup Syntax:

Terminal window
nslookup [options] [host] [server]

Linux nslookup Options:

OptionDescription
-querytype=[type]Specify the DNS query type (A, MX, NS, etc.)
-timeout=[seconds]Set the query timeout in seconds
-class=[class]Specify the DNS query class (IN for Internet)
-port=[port]Specify the DNS server port
-debugEnable debug mode for troubleshooting
-vcUse a virtual circuit when sending the query
-traceEnable trace mode to trace query route

nslookup Parameters:

ParameterDescription
hostThe host/domain to query
serverThe DNS server to query

How to use nslookup command:

Resolve a Domain Name

Terminal window
nslookup www.google.com

Queries the DNS server to resolve the domain name “www.google.com” to an IP address.

Reverse DNS Lookup

Terminal window
nslookup 8.8.8.8

Performs a reverse DNS lookup on the IP address “8.8.8.8” to find the associated domain name.

Specify DNS Server

Terminal window
nslookup yahoo.com 8.8.4.4

Queries the specified DNS server “8.8.4.4” to resolve the domain name “yahoo.com” to an IP address.

Display Additional Information

Terminal window
nslookup -query=hinfo yahoo.com

Returns the host information (HINFO) record for the domain name “yahoo.com” in addition to the usual output.

Set Timeout for Query

Terminal window
nslookup facebook.com -timeout=5

Sets a timeout of 5 seconds for the query to resolve the domain name “facebook.com” to an IP address.

Find Mail Server DNS Records

Terminal window
nslookup -type=mx yahoo.com

Retrieves the mail server (MX) DNS records for the domain name “yahoo.com”.

Suppress Display of Detailed Information

Terminal window
nslookup -sil yahoo.com

Suppresses the display of detailed information and retrieves only the results for the domain name “yahoo.com”.

Check IPv6 Address

Terminal window
nslookup -query=AAAA google.com

Queries for the IPv6 address (AAAA record) of the domain name “google.com”.

How do I use nslookup in Linux?

To use the nslookup command in Linux, execute the following command:

Terminal window
nslookup example.com

What is the purpose of using nslookup?

The nslookup command is used to query domain name servers to obtain domain name or IP address mapping or other DNS information.

Terminal window
nslookup example.com

How can I specify a custom DNS server with nslookup?

To specify a custom DNS server with nslookup, use the following command format:

Terminal window
nslookup example.com <custom_DNS_server>

How do I get more detailed information with nslookup?

To obtain more detailed information with nslookup, add the “-debug” option to the command:

Terminal window
nslookup -debug example.com

Can I perform a reverse DNS lookup with nslookup?

Yes, you can perform a reverse DNS lookup using nslookup. Simply input the IP address instead of the domain name in the command:

Terminal window
nslookup 8.8.8.8

How do I enable query retries in nslookup?

To enable query retries in nslookup, use the following command format with the desired number of retries:

Terminal window
nslookup -retry=<num> example.com

How can I set a timeout value for nslookup queries?

To set a timeout value for nslookup queries, specify the timeout duration in seconds using the “-timeout” option:

Terminal window
nslookup -timeout=<seconds> example.com

How do I perform an nslookup with a specific record type?

To perform an nslookup with a specific record type, include the record type after the domain name in the command:

Terminal window
nslookup example.com MX

Can I perform batch mode queries with nslookup?

Yes, you can perform batch mode queries by providing a file with the list of queries to nslookup using the following command:

Terminal window
nslookup -query=any - < query_list.txt

Applications of the nslookup command

  1. Querying DNS to resolve domain names
  2. Retrieving DNS records such as A, AAAA, MX, NS, and PTR records
  3. Troubleshooting DNS-related issues
  4. Checking the mapping between domain names and IP addresses