Linux nslookup Command
nslookup (Name Server Lookup) is a network management tool used to query Domain Name System (DNS) records. It helps users diagnose and resolve DNS-related issues, and is one of the commonly used command-line tools for Linux system administrators and network engineers.
The main functions of nslookup include:
- Query the IP address corresponding to a domain name
- Query the domain name corresponding to an IP address (reverse resolution)
- Query specific types of DNS records (MX, NS, SOA, etc.)
- Specify a particular DNS server for queries
Basic Syntax
The basic syntax format of the nslookup command is as follows:
nslookup [选项] [域名/IP] [DNS服务器]
Parameter Description
| Parameter | Description |
|---|---|
| Domain/IP | The domain name or IP address to query |
| DNS server | Specifies the DNS server to use (optional) |
Common Options
| Option | Description |
|---|---|
-type=TYPE |
Specify the query record type, such as A, MX, NS, etc. |
-debug |
Display debug information |
-port=PORT |
Specify the DNS server port (default 53) |
-timeout=SEC |
Set query timeout time (seconds) |
-retry=NUM |
Set number of retries |
Usage Examples
1. Basic Domain Query
Query the A record of a domain name (default):
nslookup example.com
Example output:
Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: example.com Address: 93.184.216.34
2. Query with a Specified DNS Server
Use Google's public DNS server (8.8.8.8) to query:
nslookup example.com 8.8.8.8
3. Query Specific Record Types
Query MX record (mail server):
nslookup -type=MX google.com
Query NS record (name server):
nslookup -type=NS google.com
Query TXT record:
nslookup -type=TXT google.com
4. Reverse DNS Lookup (IP to Domain)
nslookup 8.8.8.8
5. Interactive Mode
Enter interactive mode by typing nslookup without parameters:
Examples
> set type=MX
> google.com
> server 8.8.4.4
> example.com
> exit
Common DNS Record Types
| Record Type | Description | Example Command |
|---|---|---|
| A | IPv4 address record | nslookup -type=A example.com |
| AAAA | IPv6 address record | nslookup -type=AAAA example.com |
| MX | Mail exchange record | nslookup -type=MX example.com |
| NS | Name server record | nslookup -type=NS example.com |
| CNAME | Alias record | nslookup -type=CNAME www.example.com |
| TXT | Text record | nslookup -type=TXT example.com |
| SOA | Start of authority record | nslookup -type=SOA example.com |
Advanced Usage
1. Debug Mode
nslookup -debug example.com
2. Query DNS Root Servers
nslookup -type=NS .
3. Query a Specific Port
nslookup -port=8053 example.com dns-server.example.com
4. Set Timeout and Retries
nslookup -timeout=10 -retry=3 example.com
Troubleshooting
1. Query Not Responding
Possible causes:
- Network connection issues
- DNS server unavailable
- Firewall blocking DNS queries (port 53)
Solutions:
Examples
ping 8.8.8.8
# Try other DNS servers
nslookup example.com 8.8.8.8
2. What does "Non-authoritative answer" mean?
It indicates that the returned result comes from a DNS cache, not an authoritative DNS server. To get an authoritative answer, you need to query the domain's authoritative DNS servers.
3. How to query a domain's authoritative DNS servers?
nslookup -type=NS example.com
Alternative Tools
Although nslookup is still widely used, modern Linux systems recommend usingdigorhostcommand:
-
dig- A more powerful DNS query tool
dig example.com
-
host- A simpler DNS query tool
host example.com
Summary
nslookup is a simple and practical DNS query tool. After reading this article, you should be able to:
- Understand the basic usage and common options of nslookup
- Query various types of DNS records
- Diagnose basic DNS-related problems
- Understand the differences between nslookup and other DNS tools
To master nslookup, the best way is to practice more. Try querying websites you frequently visit, or your organization's domain servers, and observe the returned results of different types of DNS records.
Other Extensions
Linux Command Reference