Linux nslookup command
The nslookup
(name server lookup) command in Linux is a network utility used to query Domain Name System (DNS) servers to obtain information about domain names, such as IP addresses and other DNS records (like MX records, NS records, etc.). It is commonly used for troubleshooting DNS-related issues and verifying the resolution of domain names.
Basic Syntax of nslookup
:
[hostname]
: The domain name or IP address you want to look up.[options]
: Various options to modify the behavior ofnslookup
.
Commonly Used nslookup
Commands and Options
Basic Domain Lookup:
- The simplest form of
nslookup
queries a domain name to find its associated IP address.
Example:
Sample Output:
Explanation:
- Server: The DNS server that answered the query (in this case, Google's public DNS server
8.8.8.8
). - Non-authoritative answer: Indicates that the information was obtained from a cache (not directly from the authoritative DNS server).
- The IP addresses listed under "Address" are the resolved IPs for the domain
google.com
.
- Server: The DNS server that answered the query (in this case, Google's public DNS server
- The simplest form of
Reverse Lookup (IP to Domain):
- You can also use
nslookup
to perform a reverse DNS lookup, where you provide an IP address to find the associated domain name.
Example:
Sample Output:
Explanation: The reverse lookup query for
142.250.190.14
resolves togoogle.com
.
- You can also use
Querying a Specific DNS Server:
- You can specify a different DNS server to query instead of using the default system DNS server. This is useful for testing specific DNS servers or troubleshooting DNS resolution issues.
Example:
Sample Output:
Explanation: The query for
google.com
was made to Google's DNS server8.8.8.8
.
Querying a Specific DNS Record Type:
nslookup
allows you to specify the type of DNS record you want to query (e.g.,A
,MX
,NS
,TXT
).
Example (MX Records):
Sample Output:
Explanation: This command shows the MX (Mail Exchange) records for
google.com
, which indicate the mail servers used by the domain.
Interactive Mode:
- You can enter interactive mode in
nslookup
to query multiple domains or DNS records in a single session. - To enter interactive mode:
- Once in interactive mode, you can enter commands like:
- Set the query type:
- Query a domain:
- Set the query type:
- To exit interactive mode, type:
Sample Output:
- You can enter interactive mode in
Set Timeout and Retry Limits:
- You can set the timeout and retry behavior for DNS queries using the
-timeout
and-retry
options. - Example (Set timeout to 5 seconds and retry limit to 2):
- You can set the timeout and retry behavior for DNS queries using the
Example Scenarios:
Basic domain lookup:
Sample Output:
Reverse lookup of an IP address:
Sample Output:
Query MX records for a domain:
Sample Output:
Check the NS records for a domain:
Sample Output:
Summary of Common nslookup
Options:
Option | Description |
---|---|
-type=[record_type] | Query a specific type of DNS record (e.g., A , MX , NS , TXT ) |
-timeout=[seconds] | Set the timeout value (in seconds) for DNS queries |
-retry=[count] | Set the number of retry attempts for failed queries |
set type=[record_type] | Set the query type in interactive mode |
set timeout=[seconds] | Set the timeout value in interactive mode |
set retry=[count] | Set the retry limit in interactive mode |
Conclusion:
The nslookup
command is a useful tool for querying DNS information about domain names and IP addresses. It can be used for troubleshooting DNS resolution issues, checking the validity of DNS records (such as A, MX, and NS records), and performing reverse lookups. Whether used in interactive mode or as a simple one-time query, nslookup
is a powerful utility for network diagnostics.