The “nslookup” or the “Name Server Lookup” is a command-line utility that mostly helps system administrators. It allows them to gather information and resolve the network issues related to the DNS. For instance, translate a domain name (hostname) into its corresponding IP address and verify if the host is reachable. It converts the domain name from a human-readable form to a numerical value or IP address.
The “nslookup” comes pre-installed in most Linux distros, including Debian 12. However, it is not readily available on older distributions.
This guide discusses installing the “nslookup” on Debian 12 and sheds light on the following content.
- How to Install the “nslookup” Command on Debian 12
- How to Use the “nslookup” Command on Debian 12
- Alternatives for the “nslookup” Command
Let’s begin!
How to Install the “nslookup” Command on Debian 12
The complete process of installing the “nslookup” command on Debian 12 is as follows:
Step 1: Install “nslookup” Command on Debian 12
Users can install the “nslookup” command by installing the “dnsutils” package. To install it, execute the below-mentioned command to install the “dnsutils”. The “dnsutils” package contains the network-related tools, including the “nslookup”:
sudo apt install dnsutils
The above output shows that the “dnsutils” package is already installed on the system. However, it will install the required package with all its dependencies if not installed.
Step 2: Verify the Installation
After installing the “dnsutils”, use the following command to verify the installation of the “nslookup” utility:
nslookup -version
How to Use the “nslookup” Command on Debian 12
The “nslookup” command is currently in use for several DNS-related operations and before moving on to their details, let’s understand its syntax first.
nslookup [-option] [name | -] [server]
Here,
- The “nslookup” invokes the command.
- The “[-options]” represents a set of flags to customize the use of the “nslookup” command.
- The “[name | -]” is the argument. When no hostname is given, it uses the default name server. Or when the first argument is a hyphen “–”, the interactive mode triggers itself.
- The “[server]” specifies the DNS server for querying.
To view a list of options/flags and other details about the “nslookup” command, use the following command to trigger the man page:
man nslookup
Let’s understand more about the “nslookup” command via the following examples.
Example 1: Perform a Basic DNS Lookup
The above command only retrieves the “Type A” records for “Google.com”. The “A” stands for “Address Record” and it translates the domain names into its corresponding IP address. To retrieve all “Type” of records, run:
nslookup -type=any Google.com
From the above commands, you can see the “Non-authoritative answer”. It means the queried DNS server responded with a cached answer which can be outdated or incorrect.
Example 2: Perform a Reverse DNS Query
To perform a reverse DNS query for identifying the owner or purpose of a server based on its IP address using an IP, use the following command; here the “98.137.11.163” is the IP used by “Yahoo”:
nslookup 98.137.11.163
Example 3: Change the Default Port For DNS Query
The “DNS Server” uses the port “53” for querying. To modify this behavior and query via another port, use the following format:
nslookup -port=[port-number] [domain-name]
In the above command,
- The “-port” number tells the “nslookup” command to query using the specified port.
- The “domain-name” represents the address to query.
Note: To allow the DNS to query using a specific port, ensure that the port is open for communication. If not, the error “Connection refused” appears.
Example 4: Query MX Records
The “MX Records” store all mail server exchange data. It routes the email addresses to a specific email server. To perform a DNS query for “MX Records”, use the below command:
nslookup -type=mx Google.com
Additionally, you can save the above output to a text file for later analysis using the below command:
nslookup -type=mx Google.com > mx-records.txt
Example 5: Query Start of Authority (SOA) Records
To query the “SOA” or authoritative information to a specific domain and view the information like “Origin”, “mail addr”, “serial” and more. The “SOA” is a vital component of the DNS infrastructure that checks the authenticity and consistency of the DNS responses:
nslookup -type=soa Google.com
Example 6: Sort the DNS Query Results
You can sort the results of the DNS query. For instance, below is the command to sort the queried results according to the IP (ascending order):
nslookup -type=NS Google.com | sort -k 4
The above command shows the “NS” records (sorted by the IP address). The “NS” stands for “Name Server” and it specifies the server on which the actual DNS records are stored.
Example 7: Use the Debug Mode
The “Debug Mode” allows you to view more information on the queried domain. When used, it outputs the information about the sent packet and a more detailed result:
nslookup -debug Google.com
Alternatives for the “nslookup” Command
The “nslookup” command provides almost everything related to the DNS by querying a domain. To get more detailed information that the “nslookup” command cannot provide, explore the following alternatives for it.
The host Command
The function of the “host” command is the same as the “nslookup” command, but it includes additional flags. It comes pre-installed on Debian 12 and to view a list of flags/options, execute the following command:
host
The dig Command
The “dig” command stands up as the alternative for the “nslookup” command. It shows the results with more details and with a rich feature set, you can customize the output according to your choice. To view the flags/options of the “dig” command, run:
dig -h
That’s all for installing and using the “nslookup” on Debian 12.
Final Words
The “nslookup” is a pre-installed command-line utility. It is mainly used for DNS querying which aids the system administrators in gathering DNS information and fixing the related errors. Use the “sudo apt install dnsutils” command to install it if you cannot find it on your system. The use of the “nslookup” command is illustrated in the above guide in detail.
This guide has discussed the process to install and use the “nslookup” command on Debian 12.