What is the nslookup Command and How to Use it perfectly?
Table of contents
What is the nslookup Command?
Administrators or users troubleshooting DNS server issues often rely on this command for a quick solution. It is used to find an IP address within the DNS or Domain Name System records when you input a domain name or a hostname. Similarly, it can also be employed to search for the domain name when you enter an IP address. This process is known as reverse DNS lookup. In essence, it is a command-line tool that assists you in searching for a specific IP address or DNS record based on the provided domain name. Domain Name Systems, or DNS, can be either private or public, depending on the user’s preference.What is the Importance of the nslookup Command?
The nslookup command is a valuable tool that enables you to search for domain names and IP addresses. Additionally, users frequently encounter DNS-related issues on their devices. This tool aids in resolving these DNS problems by identifying the correct domain name or IP address. Another capability of the nslookup command is retrieving essential mail records. For instance, if someone sends an email to your domain, that information is stored within the Mail Exchange Records. The nslookup command allows you to access these records for further use, making it especially beneficial for those who incorporate email marketing into their business strategies.A Few Examples of nslookup Command
The nslookup command offers many variations, enabling you to utilize the tool based on different use cases. Some examples of this tool, along with brief descriptions, are presented here for your ease of use.- name - This displays information on the hostname or the domain name using the current default server.
- server name - This sets up a default server using the information of the current server in use.
- root - This designates the root server as the default server.
- set type=<record type> - This retrieves the record you need based on the ‘type’ you enter as the keyword. The available keywords are A, CNAME, MX, NS, PTR, or SOA, where MX equals Mail Exchange Records. If you write ‘ANY’, you will receive all available records.
- set debug - This places the tool in debug mode. Each query will have a specific response and accompanying information.
- set recurse - If there is no information available on the default server, this directs the DNS nameserver to query other servers.
- help - This provides detailed information on the various nslookup commands available and their functions.
- exit - This exits the nslookup command tool.
How to Use the nslookup Command and its Syntax?
Now that we have learned about the nslookup command and its importance, let’s explore how we can use it to our advantage.Prerequisites
There are two basic requirements for using the nslookup command. First, you need a stable internet connection, and second, you need access to the command line interface. This can be done on Windows, Mac, and Linux. You would need the Command Prompt on Windows or Terminal on Linux and macOS. The appearance will differ for each operating system.Syntax
There are two primary modes available for use with the nslookup command: interactive mode and non-interactive mode. The interactive mode is helpful when you need to gather multiple pieces of information about the domain name or the host. It enables you to add different keywords and parameters to obtain more information. Its syntax is simply nslookup. This provides you with the default server, the address, and the command line prompt where you can add further parameters from your end. This mode uses one line for each command and domain name. As for the non-interactive mode, it is designed to help you get a single query about the domain name or the host. It serves as the default setting of the nslookup command, and its basic syntax is: nslookup google.com Instead of Google, you can input any domain name whose information you wish to collect. In the non-interactive mode, you need to place all commands and domain names in the same line, unlike the interactive mode, as it is a single-query command.How Does it Work?
So, what goes on behind the nslookup command? Well, there are two answers that you might get from the command: the authoritative answer and the non-authoritative answer. The latter occurs when you have been using the command enough times to develop a cache. As a result, the tool fetches the results from the DNS cache rather than the authoritative domain server. When you use the command for the very first time, there is no cache stored, so you receive the authoritative responses on the first try. The process goes something like this: You access a website, and the browser sends a query to the DNS resolver to fetch the website’s IP address for the connection to occur on your end. The DNS resolver conveys this query to the root server with the necessary privileges, which then directs the resolver to the top-level domain (TLD) server. The TLD server takes this response to the authoritative server, where all the information about the website’s domain name and IP address is stored. The authoritative server fetches this DNS record and takes it all the way back to the browser, maintaining the desired connection on your end. Now, whenever you access the website again, the whole process will not repeat or go through irrelevant steps. Instead, the browser will go to the DNS cache, fetch the records, and provide you with a faster connection and a personalized experience. However, just like browser cache, the DNS cache can also create a hurdle of errors for you. The DNS records in the DNS cache may be outdated, resulting in non-authoritative responses that are old. This might be a problem if you are already trying to mitigate DNS-related errors on your end. You don’t need more errors piling up. But there are syntaxes that can help you get the authoritative answer even if you are not using the tool for the first time. We will discuss this further with more examples of the nslookup command.10 Ways You Can Use the nslookup Command
Here are the multiple ways you can use the nslookup command,- View NS Records
- View MX Records
- Do the Reverse DNS Lookup
- View SOA Records
- View Text Records
- View All Records
- View a Specific Name Server’s Details
- View Pointer Records
- Use a Non-Default Port for Queries
- Enable the Debug Mode