Quick take: The nslookup command queries DNS to resolve names to addresses and look up records. nslookup example.com finds its IP; nslookup -type=MX example.com finds mail servers, and adding a server (nslookup example.com 8.8.8.8) queries it directly.
Introduction
The nslookup command (name server lookup) queries DNS to resolve hostnames, look up record types, and test name servers. It is available on virtually every platform including Windows, which makes it a familiar cross-platform DNS tool, though administrators often prefer dig for its detail.
Syntax
The basic syntax of the nslookup command is:
nslookup [-type=TYPE] DOMAIN [SERVER]Common Options and Parameters
The most useful options and parameters for the nslookup command:
| Option | Description |
|---|---|
| DOMAIN | Look up the A record (IP address) by default. |
| -type=MX | Query a record type (A, AAAA, MX, NS, TXT, SOA). |
| DOMAIN SERVER | Query a specific DNS server. |
| -query=TYPE | Same as -type. |
| IP | Reverse lookup — find the hostname for an IP. |
| -debug | Show detailed query information. |
Practical Examples
Real nslookup commands you can run today:
# Resolve a domain to an IP
nslookup example.com
# Look up MX (mail) records
nslookup -type=MX example.com
# Look up TXT records
nslookup -type=TXT example.com
# Query a specific DNS server
nslookup example.com 1.1.1.1
# Reverse lookup an IP
nslookup 8.8.8.8Tips and Best Practices
- nslookup is everywhere, including Windows, so it is handy for quick cross-platform DNS checks.
- Query an external resolver (
nslookup name 8.8.8.8) to test whether a DNS change has propagated beyond your local cache. - For scripting and richer detail,
dig +shortis usually the better tool — nslookup's output is harder to parse.
Final Thoughts
nslookup is the widely available DNS lookup tool, resolving names, checking record types, and testing name servers across platforms. It is perfect for a quick check, especially on Windows. For detailed, scriptable DNS troubleshooting on Linux, reach for dig; for everyday “what does this resolve to?”, nslookup does the job.
FAQ: nslookup Command in Linux
How do I look up a domain's IP with nslookup?+
Run nslookup example.com. It returns the server it queried and the A record (IP address) for the domain.
How do I check MX records with nslookup?+
Use the type option: nslookup -type=MX example.com lists the mail exchange servers for the domain.
How do I query a specific DNS server?+
Add the server as the second argument: nslookup example.com 8.8.8.8 asks Google's resolver directly, useful for testing propagation.
How do I do a reverse DNS lookup?+
Pass an IP address: nslookup 8.8.8.8 returns the hostname associated with it via PTR records.
Should I use nslookup or dig?+
nslookup is simple and available on every platform, good for quick checks. dig gives more detailed, scriptable output and finer control, so administrators usually prefer it on Linux.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support