nslookup
nslookup is a command-line tool for querying the Domain Name System to obtain domain name or IP address mapping, or other DNS record information.
Basic Usage
Resolve a Domain to IP
nslookup piyushgarg.devOutput:
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
Name: piyushgarg.dev
Address: 1.2.3.4
Query a Specific DNS Server
nslookup piyushgarg.dev 1.1.1.1This bypasses your default resolver and asks Cloudflare directly. Useful for:
- Checking if your ISP’s resolver is stale
- Comparing response accuracy across resolvers
- Troubleshooting DNS propagation
“I can say, ‘Hey, can you please use this DNS server which is of Cloudflare?’ This will basically go to Cloudflare’s DNS on port 53 and ask for stuff.” — Day 30 CKA Video
Querying Specific Record Types
A Record (default)
nslookup piyushgarg.devMX Records
nslookup -query=MX gmail.comNS Records
nslookup -query=NS piyushgarg.devTXT Records
nslookup -query=TXT piyushgarg.devCNAME Records
nslookup -query=CNAME magic.piyushgarg.xyzInteractive Mode
nslookup
> server 8.8.8.8
> set querytype=MX
> gmail.com
> exitReverse DNS Lookup
Find the domain associated with an IP:
nslookup 8.8.8.8Common Output Fields
| Field | Meaning |
|---|---|
Server | The DNS resolver that answered the query |
Non-authoritative answer | The resolver returned a cached answer, not from the domain’s own server |
Address | The IP address(es) returned |
When nslookup Isn’t Enough
For more detailed DNS diagnostics, use dig (Linux/macOS):
dig piyushgarg.dev
# Full trace
dig +trace piyushgarg.dev
# Specific record
dig MX gmail.com
# Specific server
dig @1.1.1.1 piyushgarg.dev| Tool | Best For |
|---|---|
nslookup | Quick checks, Windows compatibility |
dig | Detailed analysis, full trace, scripting |
host | Simple one-liners on Linux |