Linux nslookup Command — Querying and Troubleshooting DNS¶
nslookup(Name Server Lookup) is a command-line utility used to query the Domain Name System (DNS) for information about domain names, IP addresses, mail servers, and other DNS records. It provides a simple way to verify DNS resolution, troubleshoot name resolution problems, perform reverse lookups, and query specific DNS servers. Although modern Linux systems recommend usingdigfor advanced DNS troubleshooting,nslookupremains widely available and commonly used across Linux, Windows, and enterprise environments. Every Linux administrator, DevOps engineer, Cloud Architect, Platform Engineer, Site Reliability Engineer (SRE), and Network Engineer should understand how to usenslookup.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand the
nslookupcommand - Query DNS records
- Perform reverse DNS lookups
- Query specific DNS servers
- Use interactive mode
- Troubleshoot DNS issues
- Compare
nslookupwithdig
Prerequisites¶
Complete:
- Linux
ipCommand - Linux
ssCommand - Linux
netstatCommand - Linux
tcpdumpCommand - Linux
tracerouteCommand - Linux
digCommand
Basic understanding of:
- DNS
- DNS Records
- IP Addressing
Why Learn nslookup?¶
Imagine users report:
- Website Not Loading
- Email Delivery Problems
- API Hostname Not Resolving
- Internal DNS Failure
The first question is:
One of the quickest tools to verify this is:
What is nslookup?¶
nslookup stands for:
It queries DNS servers to retrieve:
- IP Addresses
- Hostnames
- Mail Servers
- Name Servers
- DNS Records
DNS Resolution Process¶
nslookup verifies whether this process is working correctly.
Basic Syntax¶
Example:
Install nslookup¶
Ubuntu/Debian
RHEL/CentOS
Basic Lookup¶
Example output:
Query a Specific DNS Server¶
This sends the query directly to Google's public DNS server.
Query Cloudflare DNS¶
Reverse DNS Lookup¶
Lookup an IP address.
Returns:
Interactive Mode¶
Start interactive mode.
Prompt:
Example:
Exit:
Change Record Type¶
Inside interactive mode:
Query:
Returns:
Query MX Records¶
Non-interactive:
Query NS Records¶
Query A Records¶
Query AAAA Records¶
Query TXT Records¶
Useful for viewing:
- Sender Policy Framework (SPF) Records
- Domain Verification
- Security Policies
Query SOA Record¶
Displays the Start of Authority record.
Enterprise Example¶
Users cannot access:
Administrator runs:
Questions answered:
- Does DNS resolve?
- Which DNS server responded?
- Is the IP address correct?
Cloud Perspective¶
Cloud engineers use nslookup to verify:
- Load Balancer Hostnames
- Cloud DNS
- Private DNS Zones
- Hybrid DNS
- Service Discovery
Kubernetes Perspective¶
Test Kubernetes service resolution.
Useful for troubleshooting:
- CoreDNS
- Service Discovery
- Internal Cluster DNS
Linux Perspective¶
Basic lookup.
Specific DNS server.
Reverse lookup.
MX lookup.
Common DNS Record Types¶
| Record | Purpose |
|---|---|
| A | IPv4 Address |
| AAAA | IPv6 Address |
| MX | Mail Server |
| NS | Name Server |
| CNAME | Alias |
| TXT | Text Record |
| PTR | Reverse Lookup |
| SOA | Start of Authority |
Interactive Session Example¶
Interactive mode allows multiple queries without restarting the command.
Common nslookup Commands¶
| Command | Purpose |
|---|---|
nslookup domain | Basic lookup |
nslookup IP | Reverse lookup |
nslookup domain DNS_SERVER | Query specific DNS server |
nslookup -type=A | IPv4 lookup |
nslookup -type=AAAA | IPv6 lookup |
nslookup -type=MX | Mail servers |
nslookup -type=NS | Name servers |
nslookup -type=TXT | TXT records |
nslookup -type=SOA | SOA record |
Hands-on Lab¶
Task 1¶
Lookup Google.
Task 2¶
Lookup using Google's DNS.
Task 3¶
Perform reverse lookup.
Task 4¶
Lookup mail servers.
Task 5¶
Lookup authoritative name servers.
Task 6¶
Lookup TXT records.
Task 7¶
Use interactive mode.
Query multiple record types without exiting.
Task 8¶
Compare the output of:
and
Identify differences in output format and diagnostic information.
Production Troubleshooting¶
Problem:
Step 1
↓
Resolved?
↓
No
↓
Try:
↓
Works?
↓
Yes
↓
Problem:
↓
Investigate:
- DNS Server
- DNS Records
- Network Connectivity
- Firewall
nslookup vs dig¶
| nslookup | dig |
|---|---|
| Simple Output | Detailed Output |
| Easy to Learn | More Powerful |
| Interactive Mode | Advanced Query Options |
| Cross-Platform | Preferred on Linux |
| Good for Quick Checks | Better for Production Troubleshooting |
Common Mistakes¶
❌ Assuming the local DNS server is always correct.
✅ Test with multiple DNS servers.
❌ Forgetting to specify record types.
✅ Query the required record explicitly.
❌ Ignoring reverse lookups.
✅ Verify both forward and reverse DNS.
❌ Confusing DNS issues with network issues.
✅ Verify connectivity using ping and traceroute.
❌ Relying only on nslookup.
✅ Use dig for deeper DNS analysis.
Best Practices¶
- Use
nslookupfor quick DNS verification. - Query multiple DNS servers when troubleshooting.
- Verify both forward and reverse DNS records.
- Check MX, NS, and TXT records when diagnosing email or domain issues.
- Use
digwhen more detailed DNS diagnostics are required. - Document production DNS configurations.
- Monitor DNS changes after updates.
Interview Questions¶
Beginner¶
- What is
nslookup? - How do you perform a reverse DNS lookup?
- How do you query a specific DNS server?
- What is an MX record?
Intermediate¶
- Compare
nslookupanddig. - Explain interactive mode.
- How do you troubleshoot DNS failures using
nslookup? - What are the common DNS record types?
Architect Level¶
- Design a DNS troubleshooting workflow using
nslookup. - How would you diagnose intermittent DNS failures across multiple cloud regions?
- Explain how you would validate DNS after migrating enterprise services.
Summary¶
In this lesson, you learned:
- The
nslookupcommand - DNS Queries
- Reverse DNS Lookups
- Interactive Mode
- DNS Record Types
- Querying Specific DNS Servers
- Enterprise DNS Troubleshooting
nslookup is a simple and effective DNS diagnostic utility that enables administrators to verify hostname resolution, inspect DNS records, perform reverse lookups, and troubleshoot DNS problems. While dig offers more advanced diagnostics, nslookup remains widely used due to its simplicity, availability, and cross-platform support.
Key Takeaways¶
nslookupis a simple DNS query tool.- Query A, AAAA, MX, NS, TXT, and SOA records.
- Perform reverse lookups by querying an IP address.
- Query different DNS servers to compare responses.
- Use interactive mode for multiple DNS queries.
- Use
digfor advanced DNS troubleshooting andnslookupfor quick verification.
What's Next?¶
In the next lesson, you'll learn about curl.
You'll explore:
- What
curlis - HTTP and HTTPS Requests
- REST API Testing
- Request Headers
- Authentication
- File Downloads
- API Debugging
By the end of the lesson, you'll be able to interact with web servers, test REST APIs, inspect HTTP responses, troubleshoot web services, and automate HTTP-based workflows using one of the most widely used command-line tools in Linux.