nslookup
nslookup sends a DNS query to a name server and prints the answer: the IP of a name, the mail or name servers of a domain, or the name of an IP. It is on every Windows, Linux and macOS machine, which makes it the first DNS check in most support tickets.
84.1 Why is it used?
- Quick lookup of A, AAAA, MX, NS, SOA, TXT or PTR records from any OS.
- Ask a specific server (8.8.8.8, 1.1.1.1, your own DNS) to see if the problem is the local resolver or the domain.
- Windows: built in, Microsoft's own version. Linux: dnsutils / bind-utils package. macOS: built in. Linux and macOS run the BIND 9 version with slightly different sub-commands.
84.2 How it works: the journey of one query
- Step 1
1.Your PC -> resolver 8.8.8.8: A? example.com
- Step 2
2.Not in cache: resolver -> root, gets the .com TLD server
- Step 3
3.Resolver -> TLD .com, gets the authoritative server
- Step 4
4.Resolver -> authoritative, gets A 104.20.23.154
- Step 5
5.Resolver -> your PC: the answer, labelled "Non-authoritative answer"
The resolver did not own the zone, so the answer is non-authoritative; that is normal
84.3 Windows: command-line modes
nslookup example.com 8.8.8.8nslookup -type=AAAA example.com 8.8.8.8nslookup 8.8.8.8 8.8.8.8nslookup -debug -type=A+AAAA ^ -nosearch -recurse example.com 8.8.8.8C:\> nslookup example.com 8.8.8.8Non-authoritative answer:Server: dns.googleAddress: 8.8.8.8 Name: example.comAddresses: 2606:4700:91b5:72db:f2a8:0:ef6b:ff98 104.20.23.154 172.66.147.243C:\> nslookup 8.8.8.8 8.8.8.8Server: dns.googleAddress: 8.8.8.8 Name: dns.googleAddress: 8.8.8.8C:\> nslookup -debug -type=A+AAAA -nosearch -recurse example.com 8.8.8.8Got answer: HEADER: opcode = QUERY, id = 2, rcode = NOERROR header flags: response, want recursion, recursion avail. QUESTIONS: example.com, type = A, class = IN ANSWERS: -> example.com internet address = 172.66.147.243 ttl = 300 (5 mins)| Form | What it does |
|---|---|
| nslookup NAME | Lookup via the default server |
| nslookup NAME 1.1.1.1 | Lookup via this server |
| nslookup 8.8.8.8 | Reverse lookup (PTR) |
| nslookup | Interactive mode, default server |
| nslookup - 1.1.1.1 | Interactive mode, this server as default |
| -type=AAAA / -type=A+AAAA | Only this record type / IPv4 + IPv6 |
| -debug -nosearch -recurse | Any set option works on the command line with a leading - |
84.4 Windows: interactive commands
nslookup - 8.8.8.8> set all> example.com> server 1.1.1.1> lserver 8.8.8.8> set type=NS> example.com.> help> exitC:\> nslookup - 8.8.8.8Default Server: dns.googleAddress: 8.8.8.8 > Set options: nodebug defname search recurse nod2 novc port=53 type=A+AAAA class=IN timeout=2 retry=1> Default Server: one.one.one.oneAddress: 1.1.1.1 > Default Server: dns.googleAddress: 8.8.8.8> > Non-authoritative answer:Server: dns.googleAddress: 8.8.8.8 example.com nameserver = elliott.ns.cloudflare.comexample.com nameserver = hera.ns.cloudflare.com| Command | Meaning |
|---|---|
| NAME / NAME SERVER | Lookup via default server / via SERVER for this one query |
| server SRV | Change default server, resolving SRV via the current server |
| lserver SRV | Change default server, resolving SRV via the initial server (use when the current one is broken) |
| root | Switch to the root server |
| \server | Treat a command word as a host name |
| finger USER [> FILE] | Query a finger server |
| ls / view FILE | Zone listing / sort and show a saved ls file |
| help or ?, exit | Command summary, leave the prompt |
- Windows default type is A+AAAA (from set all); default timeout 2 s, retry 1.
- A trailing dot (example.com.) makes the name absolute so no search suffix is added.
84.5 Windows: ls (zone transfer)
nslookup - 8.8.8.8> ls example.com> ls -d example.com> ls -t MX example.com> exitC:\> nslookup - 8.8.8.8Default Server: dns.googleAddress: 8.8.8.8 > *** Can't list domain example.com: Server failedThe DNS server refused to transfer the zone example.com to your computer. If thisis incorrect, check the zone transfer security settings for example.com on the DNSserver at IP address 8.8.8.8. [dns.google]> *** Can't list domain example.com: Server failed[dns.google]- ls asks for an AXFR (whole zone). Public servers refuse it, which is the correct behaviour.
- Options: -t TYPE, -a (CNAME), -d (all, = -t ANY), -h (HINFO), -s (WKS), > FILE to save, >> FILE to append.
84.6 Windows: set options and record types
| Option | Use |
|---|---|
| set all | Show settings and current server |
| [no]debug, [no]d2 | Debug / exhaustive debug output |
| type=RR, querytype=RR | Record type (default A, Windows shows A+AAAA) |
| [no]recurse | Ask the server for recursion or not |
| [no]vc | TCP instead of UDP (default UDP) |
| port=N | Non-standard DNS port (default 53) |
| timeout=SEC, retry=N | Increase for slow servers (defaults 2 and 1) |
| domain, [no]search, srchlist=D1/D2 | Search suffixes (max 6 domains) |
| class=IN|CHAOS|HESIOD|ANY | Record class |
nslookup - 8.8.8.8> set type=SOA> example.com.> set querytype=TXT> example.com.> set type=MX> google.com.example.com primary name server = elliott.ns.cloudflare.com responsible mail addr = dns.cloudflare.com serial = 2418004112 refresh = 10000 (2 hours 46 mins 40 secs) retry = 2400 (40 mins) expire = 604800 (7 days) default TTL = 1800 (30 mins)example.com text = "_k2n1y4vw3qtb4skdx9e7dxt97qrmmq9"example.com text = "v=spf1 -all"google.com MX preference = 10, mail exchanger = smtp.google.com- Daily types: A, CNAME, MX, NS, PTR, SOA, TXT (plus ANY, HINFO).
- MB, MG, MINFO, MR, GID, UID, UINFO, WKS are old experimental types, almost never used today.
84.7 Linux/macOS (BIND 9): command line
Lab: own BIND server n084-dns 192.168.104.53 (zone n084.lab, also on port 5353, forwarder 8.8.8.8), client n084-pc 192.168.104.10. Test only against your own servers or public resolvers.
cat /etc/resolv.confnslookup wwwnslookup 192.168.104.80nslookup -query=hinfo -timeout=10 pc1nslookup -port=5353 shop 192.168.104.53nslookup nothere; echo exit=$?nslookup -version$ cat /etc/resolv.confnameserver 192.168.104.53search n084.lab$ nslookup wwwServer: 192.168.104.53Address: 192.168.104.53#53 Name: www.n084.labAddress: 192.168.104.80Name: www.n084.labAddress: fd00:84::80$ nslookup 192.168.104.8080.104.168.192.in-addr.arpa name = www.n084.lab.$ nslookup -query=hinfo -timeout=10 pc1Server: 192.168.104.53Address: 192.168.104.53#53 pc1.n084.lab hinfo = "x86_64" "Linux"$ nslookup -port=5353 shop 192.168.104.53Server: 192.168.104.53Address: 192.168.104.53#5353 shop.n084.lab canonical name = www.n084.lab.Name: www.n084.labAddress: 192.168.104.80$ nslookup nothere; echo exit=$?Server: 192.168.104.53Address: 192.168.104.53#53 ** server can't find nothere: NXDOMAIN exit=1$ nslookup -versionnslookup 9.18.25- The search domain n084.lab was appended to www; no "Non-authoritative" line because ns1 owns the zone.
- NXDOMAIN gives exit status 1, handy in scripts.
84.8 Linux/macOS (BIND 9): interactive differences
- www -> search list added, answer found; www. (trailing dot) -> absolute name -> NXDOMAIN.
- "example.com 8.8.8.8" in interactive mode: BIND 9.18 ignored the server and still asked the lab server. Use the server command instead.
- server 8.8.8.8 switched to Google; lserver 192.168.104.53 switched back.
- ls, root, finger, view print "not implemented"; help prints "not yet implemented".
Instead of ls, use dig AXFR (the lab server allows transfers only inside the lab):
dig axfr n084.lab @192.168.104.53 \ +nocmd +nostats$ dig axfr n084.lab @192.168.104.53 +nocmd +nostatsn084.lab. 300 IN SOA ns1.n084.lab. admin.n084.lab. 2026110901 3600 600 86400 300n084.lab. 300 IN NS ns1.n084.lab.n084.lab. 300 IN MX 10 mail.n084.lab.n084.lab. 300 IN TXT "v=spf1 mx -all"_ldap._tcp.n084.lab. 300 IN SRV 0 100 389 ns1.n084.lab.mail.n084.lab. 300 IN A 192.168.104.25ns1.n084.lab. 300 IN A 192.168.104.53pc1.n084.lab. 300 IN A 192.168.104.10pc1.n084.lab. 300 IN HINFO "x86_64" "Linux"shop.n084.lab. 300 IN CNAME www.n084.lab.www.n084.lab. 300 IN A 192.168.104.80www.n084.lab. 300 IN AAAA fd00:84::80n084.lab. 300 IN SOA ns1.n084.lab. admin.n084.lab. 2026110901 3600 600 86400 30084.9 recurse vs norecurse: testing the cache
- Step 1
1.rndc flush on ns1: cache empty
- Step 2
2.nslookup -norecurse example.com -> ns1 checks only its cache -> No answer
- Step 3
3.nslookup example.com (recursive) -> ns1 asks 8.8.8.8 and caches the answer
- Step 4
4.nslookup -norecurse example.com again -> answered from the cache
rndc flush # ns1 (lab server)nslookup -norecurse example.comnslookup example.comnslookup -norecurse example.comdns$ rndc flush && echo flushedflushed$ nslookup -norecurse example.comServer: 192.168.104.53Address: 192.168.104.53#53 Non-authoritative answer:*** Can't find example.com: No answer$ nslookup example.comNon-authoritative answer:Name: example.comAddress: 172.66.147.243Name: example.comAddress: 104.20.23.154Name: example.comAddress: 2606:4700:9765:72db:f20c:0:ef6b:ff98$ nslookup -norecurse example.comNon-authoritative answer:Name: example.comAddress: 104.20.23.154Name: example.comAddress: 172.66.147.243Name: example.comAddress: 2606:4700:9765:72db:f20c:0:ef6b:ff9884.10 Linux/macOS (BIND 9): set keywords
nslookup> set all> set cl=CH> set ty=TXT> version.bind> set class=IN> set q=NS> n084.labSet options: novc nodebug nod2 search recurse timeout = 0 retry = 3 port = 53 ndots = 1 querytype = A class = IN srchlist = n084.labversion.bind text = "9.18.49"n084.lab nameserver = ns1.n084.lab.| Keyword | Meaning |
|---|---|
| class=IN|CH|HS|ANY (cl) | Record class; CH + TXT version.bind reveals the BIND version |
| querytype=T (q), type=T (ty) | Record type |
| [no]recurse (rec) | Ask for recursion; norecurse = cache only |
| [no]search, domain=NAME, ndots=N | Search list behaviour; with N dots the name is tried as-is first |
| [no]vc | TCP instead of UDP (server log shows +T) |
| [no]debug (deb), [no]d2 | Full packet display / extra debugging |
| port=N (po), retry=N, timeout=N | Port, retries, wait in seconds |
| [no]fail | On SERVFAIL stop (fail) or try the next server (nofail, default) |
84.11 Common mistakes
- Reading "Non-authoritative answer" as wrong or unsafe: it only means the answer came from a resolver's cache or recursion. For an authoritative answer find the NS with -type=NS and query that server.
- Reading "No answer" with -norecurse as a wrong name: it only means the name is not in the cache yet (not NXDOMAIN).
- Forgetting the search list: www may become www.n084.lab; add a trailing dot for an exact name.
- Parsing nslookup output in scripts: its format is not stable, use dig.
84.12 Interview tips
- Debug flow: same name via the default server and via 8.8.8.8 -> local resolver problem or domain problem.
- Then check -type=MX / NS / SOA and add -debug for header, flags and TTL.
- ls = zone transfer (AXFR); public servers refuse it, BIND nslookup does not have it (use dig axfr).
- For scripting prefer dig.