This advanced guide explains how to use nslookup beyond basic lookups—covering query types, server selection, debugging, and scripting—so you can diagnose DNS issues and inspect records with precision. You'll learn the exact commands, how to read the output, and how to apply them to real-world troubleshooting.
What nslookup Actually Does
nslookup is a command-line tool for querying the Domain Name System (DNS). It sends a DNS query to a resolver (usually your local DNS server) and displays the response. In interactive mode, you can issue multiple queries in one session; in non-interactive mode, you run a single query and exit. Most operating systems (Windows, macOS, Linux) include it, though modern alternatives like dig and host are preferred on Unix-like systems.
Understanding nslookup is useful for network administrators, developers, and anyone debugging why a domain won't resolve or why email is misrouted. It lets you see the raw DNS records—A, AAAA, MX, NS, TXT, CNAME—and verify propagation or delegation.
Interactive vs. Non-Interactive Mode
You can run nslookup in two ways. In non-interactive mode, type the query directly on the command line:
nslookup example.com
This returns the A record (IPv4 address) for example.com. To query a specific record type, use the -type option:
nslookup -type=MX example.com
Interactive mode is entered by typing nslookup with no arguments. You'll see a > prompt. Here you can set options and query multiple domains without restarting. For example:
> set type=MX > example.com > set type=NS > example.org
Interactive mode is efficient for repeated queries and debugging sessions.
Essential Query Types and Options
Beyond A and AAAA records, nslookup can query many DNS record types. The most useful ones for troubleshooting:
- A – IPv4 address (default)
- AAAA – IPv6 address
- MX – mail exchange servers
- NS – authoritative name servers
- TXT – text records (SPF, DKIM, verification)
- CNAME – canonical name (alias)
- SOA – start of authority (zone metadata)
- PTR – reverse lookup (IP to hostname)
To set the query type, use set type= or set q= (short for query). For example, set type=AAAA queries IPv6 addresses. You can also use the -type flag in non-interactive mode.
Other useful options:
set timeout=2– wait 2 seconds for a reply (default 5)set retry=3– retry up to 3 times (default 2)set debug– show full query and response packetsset d2– even more verbose debug outputset recurse– ask the server to recursively resolve (default on)set norecurse– ask for only what the server has cached
Querying a Specific DNS Server
By default, nslookup uses the DNS server configured on your system. To query a specific server (e.g., Google's 8.8.8.8 or Cloudflare's 1.1.1.1), add the server address as the second argument in non-interactive mode:
nslookup example.com 8.8.8.8
In interactive mode, use the server command:
> server 8.8.8.8 > example.com
This is critical when you suspect your local DNS server is returning stale or incorrect results. Comparing responses from different resolvers can isolate the problem.
Reverse DNS Lookups
To find the hostname associated with an IP address, use a PTR query. In non-interactive mode:
nslookup 8.8.8.8
This returns the PTR record for that IP (e.g., dns.google). In interactive mode, set type to PTR and enter the IP. Reverse lookups are used for email server validation, logging, and security checks.
Debugging and Verbose Output
When a query fails, you need more than the default error message. Enable debug mode to see the raw DNS packets:
nslookup -debug example.com
Or in interactive mode:
> set debug > example.com
Debug output shows the query sent, the response received, and any errors. Look for lines like Got answer: and HEADER: to see the response flags. Common flags include:
aa– Authoritative Answer (server is authoritative for the domain)tc– TrunCated (response was too large for UDP, retry over TCP)rd– Recursion Desired (client asked for recursive resolution)ra– Recursion Available (server can do recursive queries)
Debug mode is invaluable for understanding why a query returns NXDOMAIN (domain doesn't exist) or SERVFAIL (server failure).
Common Problems and How to Fix Them
Here are typical nslookup issues and their causes:
- Non-authoritative answer – This is normal. It means the server returned a cached response, not from the authoritative name server. Use
set norecurseor query the authoritative NS directly to get the authoritative answer. - Server can't find example.com: NXDOMAIN – The domain does not exist, or the DNS server is not configured for that zone. Check the domain spelling and try querying a public resolver.
- *** Can't find server name for address 8.8.8.8: Non-existent domain – This occurs when nslookup tries to reverse-resolve the server IP and fails. It's often harmless; you can ignore it or use the IP directly.
- Connection timed out; no servers could be reached – The DNS server is unreachable. Check your network connection, firewall, or DNS server IP.
- Query refused – The server refuses to answer, often due to access control. Try a different server.
Scripting with nslookup
You can use nslookup in scripts to automate DNS checks. In batch mode, feed commands via stdin:
echo "set type=MX\nexample.com" | nslookup
Or use a file:
nslookup < commands.txt
For more robust scripting, consider using dig or host on Linux/macOS, as they provide more consistent output and exit codes. On Windows, nslookup is still the standard built-in tool.
Limitations and Alternatives
nslookup has limitations: it doesn't support DNSSEC validation, and its output formatting can be inconsistent across platforms. For advanced DNS debugging, use dig (Linux/macOS) or Resolve-DnsName (PowerShell). These tools offer more detailed output and options like tracing the resolution path. However, nslookup remains a quick, universal tool for basic and intermediate DNS queries.
Frequently Asked Questions
How do I query a specific record type with nslookup?
Use nslookup -type=MX example.com in non-interactive mode, or in interactive mode type set type=MX then the domain. Replace MX with any record type like AAAA, TXT, or NS.
Why does nslookup say "Non-authoritative answer"?
It means the response came from a cache, not from the authoritative name server for that domain. This is normal when using a recursive resolver. To get an authoritative answer, query the domain's NS servers directly.
How do I use nslookup to check DNS propagation?
Query multiple public DNS servers (like 8.8.8.8 and 1.1.1.1) and compare the results. If they differ, propagation is still in progress. Use nslookup example.com 8.8.8.8 and repeat with other servers.
What does "Connection timed out" mean in nslookup?
It means the DNS server did not respond within the timeout period. Check your network connection, firewall settings, and that the server IP is correct. Try pinging the server or using a different DNS server.
Can nslookup query IPv6 addresses?
Yes, use set type=AAAA or -type=AAAA to query IPv6 address records. The output will show the IPv6 address if it exists.
Is nslookup deprecated?
Not officially, but many network professionals prefer dig or host for more detailed output and features. nslookup is still included in most operating systems and remains useful for quick checks.