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.dev

Output:

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.1

This 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.dev

MX Records

nslookup -query=MX gmail.com

NS Records

nslookup -query=NS piyushgarg.dev

TXT Records

nslookup -query=TXT piyushgarg.dev

CNAME Records

nslookup -query=CNAME magic.piyushgarg.xyz

Interactive Mode

nslookup
> server 8.8.8.8
> set querytype=MX
> gmail.com
> exit

Reverse DNS Lookup

Find the domain associated with an IP:

nslookup 8.8.8.8

Common Output Fields

FieldMeaning
ServerThe DNS resolver that answered the query
Non-authoritative answerThe resolver returned a cached answer, not from the domain’s own server
AddressThe 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
ToolBest For
nslookupQuick checks, Windows compatibility
digDetailed analysis, full trace, scripting
hostSimple one-liners on Linux

Source