The Wayback Machine - https://web.archive.org/web/20240809143331/https://www.geeksforgeeks.org/nslookup-command-in-linux-with-examples/
Open In App

Nslookup Command in Linux with Examples

Last Updated : 09 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

Nslookup (stands for “Name Server Lookup”) is a useful command for getting information from the DNS server. It is a network administration tool for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or any other specific DNS record. It is also used to troubleshoot DNS-related problems.

In easy words, imagine the internet as a giant neighborhood. Websites are like houses, but instead of street names, they have easy-to-remember addresses like “google.com”. However, computers communicate using numbers, so they need a way to find these houses. That’s where DNS comes in. It acts like a phonebook, translating those friendly website names into numerical addresses (IP addresses) that computers can understand.

Now, the nslookup command is like a special tool you can use to explore this phonebook. It lets you ask questions about websites and how they’re connected. You can use it to:

  • Look up a website’s address: Just like looking up a phone number in a phonebook, you can use nslookup to find the IP address of a website.
  • Troubleshoot problems: If you’re having trouble accessing a website, nslookup can help you pinpoint where the issue might lie.
  • Learn more about domain configurations: By using nslookup, you can discover details about a website’s domain, such as the servers responsible for managing it.

Syntax of the nslookup Command in Linux

The syntax of the nslookup command is relatively straightforward, typically taking the form:

nslookup [option] [domain]

Where:

  • [options] refer to additional parameters that modify the behavior of the command.
  • [domain] denotes the domain name or IP address to be queried.

Options of nslookup command:  

Options Description
-domain=[domain-name] allows you to change the default DNS name.
-debug enables the display of debugging information.
-port=[port-number] Use the -port option to specify the port number for queries. By default, nslookup uses port 53 for DNS queries
-timeout=[seconds] you can specify the time allowed for the DNS server to respond. By default, the timeout is set to a few seconds
-type=a Lookup for a record 
We can also view all the available DNS records for a particular record using the -type=a option
-type=any  Lookup for any record 
We can also view all the available DNS records using the -type=any option. 
-type=hinfo  displays hardware-related information about the host. It provides details about the operating system and hardware platform
-type=mx   Lookup for an mx record 
MX (Mail Exchange) maps a domain name to a list of mail exchange servers for that domain. The MX record says that all the mails sent to “google.com” should be routed to the Mail server in that domain. 
-type=ns Lookup for an ns record 
NS (Name Server) record maps a domain name to a list of DNS servers authoritative for that domain. It will output the name serves which are associated with the given domain. 
-type=ptr  used in reverse DNS lookups. It retrieves the Pointer (PTR) records, which map IP addresses to domain names.
-type=soa Lookup for a soa record 
SOA record (start of authority), provides the authoritative information about the domain, the e-mail address of the domain admin, the domain serial number, etc… 

Performing a basic DNS lookup

Syntax:

nslookup example.com

Example:

nslookup google.com

nslookup followed by the domain name will display the “A Record” (IP Address) of the domain. Use this command to find the address record for a domain. It queries domain name servers and gets the details. 

nslookup google.com

nslookup google.com

Performing a reverse DNS lookup

Syntax:

nslookup [IP Address]

Example:

nslookup 192.168.0.10

 You can also do the reverse DNS look-up by providing the IP Address as an argument to nslookup. 

nslookup 192.168.0.10

nslookup 192.168.0.10

Using `-type=any` option 

Syntax:

>
nslookup -type=any google.com

 Lookup for any record We can also view all the available DNS records using the -type=any option. 

nslookup -type=any google.com

nslookup -type=any google.com

Using `-type=soa` option 

Syntax:

nslookup -type=soa redhat.com

Lookup for a soa record SOA record (start of authority), provides the authoritative information about the domain, the e-mail address of the domain admin, the domain serial number, etc… 

nslookup -type=soa redhat.com

nslookup -type=soa redhat.com

Using `-type=ns` option 

Syntax:

nslookup -type=ns google.com

 Lookup for an ns record. NS (Name Server) record maps a domain name to a list of DNS servers authoritative for that domain. It will output the name serves which are associated with the given domain. 

nslookup -type=ns google.com

nslookup -type=ns google.com

Using `-type=a` option 

Syntax:

nslookup -type=a google.com

Lookup for a record. We can also view all the available DNS records for a particular record using the -type=a option. 

nslookup -type=a google.com

nslookup -type=a google.com

Using `-type=mx` option 

Syntax:

nslookup -type=mx google.com

Lookup for an mx record. MX (Mail Exchange) maps a domain name to a list of mail exchange servers for that domain. The MX record says that all the mails sent to “google.com” should be routed to the Mail server in that domain. 

nslookup -type=mx google.com

nslookup -type=mx google.com

Using `-type=txt` option 

Syntax:

nslookup -type=txt google.com

Lookup for a txt record. TXT records are useful for multiple types of records like DKIM, SPF, etc. You can find all TXT records configured for any domain using the command below. 

nslookup -type=txt google.com

nslookup -type=txt google.com

Nslookup Command in Linux – FAQs

What is nslookup command used for?

The `nslookup` command is a network administration tool used for querying the Domain Name System (DNS) to obtain domain name or IP address mapping information. It’s commonly used to troubleshoot DNS-related issues, check DNS records, and diagnose network problems.

How do I use nslookup to find the IP address of a domain?

To find the IP address associated with a domain using `nslookup`, simply type `nslookup domain_name` in your terminal or command prompt, replacing “domain_name” with the actual domain you want to look up. The command will return the corresponding IP address(es) for that domain.

What are the common options or parameters used with nslookup?

Some common options or parameters used with `nslookup` include:

  • -query=type: Specify the type of DNS record to query (e.g., A, MX, NS).
  • -server=server: Specify the DNS server to use for the query.
  • -timeout=seconds: Set the timeout for the query.
  • -debug: Enable debug mode to display detailed information.
  • -help or ?: Display a help message with available options.

Why do I sometimes get “Non-authoritative answer” in nslookup results?

When `nslookup` returns a “Non-authoritative answer,” it means the DNS server queried is not the primary authoritative server for the domain in question. Instead, it obtained the information from a cached or secondary server. This is common in recursive DNS setups where servers cache responses for performance reasons.

What should I do if nslookup fails to resolve a domain name?

If `nslookup` fails to resolve a domain name, there are several steps you can take to troubleshoot the issue:

  • Check your internet connection and ensure DNS servers are reachable.
  • Verify the domain name spelling and try again.
  • Check your DNS server settings or try querying a different DNS server.
  • Look for any firewall or network configuration issues that might be blocking DNS queries.
  • Consider using other tools like dig or host for additional troubleshooting.

Conclusion

In this article we have discussed the `nslookup` command which is a variable tool for querying the DNS server and obtaining information about domain name or IP address mapping. We have studied that it is very useful for troubleshooting DNS-related issues. We have also discussed options like -type=a, -type=any, -type=mx, -type=ns, -type=ptr, and -type=soa. Overall, we can say that by using nslookup information, administrators can gain insights into the DNS infrastructure and resolve DNS-related problems efficiently.



Previous Article
Next Article

Similar Reads

Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
select command in Linux with examples
select command in Linux is used to create a numbered menu from which a user can select an option. If the user enters a valid option then it executes the set of command written in select block and then ask again to enter a number, if a wrong option is entered it does nothing. If user enters nothing and simply press 'enter' the option menu gets print
1 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
1 min read
comm command in Linux with examples
comm compare two sorted files line by line and write to standard output; the lines that are common and the lines that are unique. Suppose you have two lists of people and you are asked to find out the names available in one and not in the other, or even those common to both. comm is the command that will help you to achieve this. It requires two so
5 min read
cmp Command in Linux with examples
cmp command in Linux/UNIX is used to compare the two files byte by byte and helps you to find out whether the two files are identical or not. When cmp is used for comparison between two files, it reports the location of the first mismatch to the screen if difference is found and if no difference is found i.e the files compared are identical.cmp dis
5 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
3 min read
df Command in Linux with examples
There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e df command that displays the amount of disk space available on the fi
8 min read
help Command in Linux with examples
If you are new to LINUX operating system and having trouble dealing with the command-line utilities provided by LINUX then you really need to know first of all about the help command which as its name says help you to learn about any built-in command. help command as told before just displays information about shell built-in commands. Here's the sy
3 min read
fgrep command in Linux with examples
The fgrep filter is used to search for the fixed-character strings in a file. There can be multiple files also to be searched. This command is useful when you need to search for strings which contain lots of regular expression metacharacters, such as "^", "$", etc. Syntax: fgrep [options] [ -e pattern_list] [pattern] [file] Options with Description
3 min read
Article Tags :
three90RightbarBannerImg