nslookup – DNS Query Tool
What is nslookup?
Definition: nslookup
is a command-line tool used to query Domain Name System (DNS) servers to obtain information about domain names, IP addresses, and various DNS records.
Purpose / Use Cases:
- Troubleshooting DNS resolution issues
- Verifying DNS records (A, MX, CNAME, etc.)
- Testing DNS server responses
Basic nslookup Usage
-
Query a Domain Name to Get Its IP Address
nslookup example.com
Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: example.com Address: 93.184.216.34
Interpretation: Shows which DNS server responded and the IP address for the domain. -
Reverse Lookup: Query an IP to Find Its Domain Name
nslookup 8.8.8.8
Server: your.local.dns.server Address: 192.168.1.1 Name: dns.google Address: 8.8.8.8
Use Case: Verifies PTR (Pointer) records for IPs, useful in email and network troubleshooting.
Interactive vs. Non-Interactive Mode
- Non-Interactive: Type a single query and get an immediate answer (e.g.,
nslookup google.com
). - Interactive: Enter
nslookup
alone to get a prompt. Then issue multiple queries and use advanced options.> nslookup > set type=MX > gmail.com
Query Types
Type | Description |
---|---|
A | Maps domain name to IPv4 address. |
AAAA | Maps domain name to IPv6 address. |
PTR | IP address to domain name (reverse DNS). |
MX | Mail Exchange records (mail server for the domain). |
NS | Name Server records (authoritative DNS servers). |
CNAME | Canonical Name records (aliases). |
Example (interactive):
> nslookup > set type=MX > gmail.comOutput: Lists mail servers for gmail.com.
Changing DNS Servers in nslookup
Specify a DNS server for a query: nslookup example.com 8.8.8.8
In interactive mode:
> server 1.1.1.1
(switches queries to Cloudflare’s DNS)
Advanced Query Options
- Set Query Type:
set type=MX
orset q=NS
- View all records (any):
set type=ANY
- Check authoritative answer: Some responses show “authoritative answer” if the DNS server is official for that domain.
Interpreting nslookup Output
Field | Meaning |
---|---|
Server | DNS server that responded. |
Non-authoritative answer | Response from a cache or non-original source. |
Authoritative answer | Response direct from the primary DNS server. |
Name/Address | The answer to your query. |
Common Troubleshooting Scenarios
- DNS Resolution Failures: No response, timeout, or incorrect IP = DNS issues or misconfigurations.
- Check if a DNS record exists: Verify A, MX, CNAME, etc.
- Test Alternate DNS Servers: Helps distinguish between client, server, or upstream problems.
Limitations of nslookup
- Some platforms (notably Unix/Linux) prefer
dig
orhost
for more detailed diagnostics. - Limited scripting capability compared to
dig
. - Does not support all modern DNSSEC validation features.
Platform Differences
Platform | Availability | Notes |
---|---|---|
Windows | Built-in | Always available |
Linux/macOS | Common, but sometimes replaced by dig | Syntax and features are similar, output formatting can differ |
Example: Verifying Mail Server for a Domain
nslookup -type=mx example.com
example.com mail exchanger = 10 mail.example.com.Use Case: Verifies which mail servers are used for a domain (useful for email setup/troubleshooting).
Exam Tips and Key Points
- Remember the difference between “authoritative” and “non-authoritative” answers.
- Know how to use
set type=
for different DNS records. - Be able to test with different DNS servers (e.g.,
nslookup example.com 1.1.1.1
). - Practice interpreting output for both success and failure cases.
- Understand basic troubleshooting with reverse lookups and alternate DNS.
Comparison Table: nslookup vs. dig vs. host
Feature | nslookup | dig (Domain Information Groper) | host |
---|---|---|---|
Purpose | Basic DNS queries and troubleshooting | Detailed DNS diagnostics and scripting | Simple forward and reverse DNS lookups |
Availability | Default on Windows, most Unix systems | Standard on Linux/Unix; may require install | Standard on Linux/Unix; may require install |
Syntax Simplicity | Easy | Slightly more advanced | Very easy |
Query Types | All record types (A, MX, CNAME, etc.) | All record types, full control | Most common types |
Batch/Script Support | Limited | Excellent (can use in scripts, +short output) | Limited |
Output Detail | Basic to moderate | Very detailed (headers, sections, timings, etc.) | Minimal |
DNSSEC Support | Limited | Full DNSSEC diagnostic info | Some |
Authoritative Answers | Yes (shown in output) | Yes (full section in output) | Yes (minimal display) |
Best Use Case | Quick checks, Windows environments | In-depth DNS troubleshooting, scripts | Quick lookup, scripts |
Sample Command | nslookup example.com | dig example.com | host example.com |
Sample Troubleshooting Steps Using nslookup
Scenario: John cannot access www.example.com from his PC.
-
Step 1: Check DNS Resolution
nslookup www.example.com
Expected Output: Should display an IP address for the domain.
If fails: Note any “timed out,” “server can’t find,” or “NXDOMAIN” errors. -
Step 2: Test Alternate DNS Server
nslookup www.example.com 8.8.8.8
Purpose: Checks if problem is with John’s default DNS or upstream server.
If this works: Local DNS server issue; consider reconfiguring DNS settings. -
Step 3: Reverse Lookup to Verify PTR Record
nslookup [IP address]
Purpose: Checks if the IP for the site has a reverse DNS entry (helps in mail troubleshooting). -
Step 4: Query for Other Record Types
MX Record (Mail Exchange):
nslookup -type=mx example.com
NS Record (Name Server):
nslookup -type=ns example.com
-
Step 5: Enter Interactive Mode for Multiple Queries
nslookup > set type=any > example.com > server 1.1.1.1 > set type=mx > example.com
Purpose: Batch test various records and switch DNS servers without re-running the command. -
Step 6: Interpret Output
- Non-authoritative answer: Response came from a cache (not original DNS).
- No answer/timeout: Possible connectivity issue, firewall blocking, or DNS misconfiguration.
- Mismatched or unexpected IP: Possible DNS poisoning/spoofing or outdated DNS record.
-
Step 7: Further Troubleshooting
dig www.example.com
Try another tool for detailed diagnostics.
ping 8.8.8.8
Check connectivity to DNS server.
ipconfig /flushdns
Flush DNS cache (Windows).
Exam Tips
- Remember the differences in output and strengths for each tool.
- Practice using
set type=
in nslookup for A, MX, CNAME, NS records. - Know how to specify an alternative DNS server in your queries.
- Be comfortable with interpreting “authoritative” vs. “non-authoritative” answers.