How the nslookup Command Queries DNS Servers
The nslookup command sends DNS queries straight to a server, bypassing the Windows client cache and hosts file. Learn how it resolves names and reads answers.
The nslookup command is a diagnostic client that sends a DNS query directly to a DNS server and prints the server’s response. It does not consult the Windows DNS client cache, the local hosts file, or the NRPT (Name Resolution Policy Table). When nslookup returns a different address than ping or a browser, the difference is usually not an error in DNS; it is a difference in which resolver path was used. Understanding that separation is the key to reading nslookup output correctly.
What nslookup bypasses in the Windows resolver stack
Windows resolves a name through several layers before a packet leaves the machine. The DNS Client service (Dnscache) checks the local hosts file, the DNS client cache, and any policy table entries, then forwards the query to the configured DNS servers. nslookup does not use Dnscache for the query itself. It opens its own UDP or TCP socket to the DNS server named in its configuration and asks that server directly.
This means a stale entry in the DNS client cache cannot affect an nslookup result, and an entry in the hosts file cannot either. If ping returns 10.0.0.5 from a hosts file line while nslookup returns 203.0.113.20 from the DNS server, both tools are correct about their own path. The hosts file wins for ordinary applications because the DNS Client service reads it first. nslookup never sees it.
The same applies to negative answers. A name that fails in a browser may still resolve in nslookup if the browser is using a different resolver, such as DNS-over-HTTPS configured in the browser itself. nslookup only knows about the DNS servers configured in Windows or the server named on its command line.
Reading the default output
Run nslookup with a single name:
nslookup example.com
The output has two parts. The first lines show the DNS server that answered and its address. The second part shows the answer:
Server: dns.google
Address: 8.8.8.8
Non-authoritative answer:
Name: example.com
Addresses: 93.184.216.34
The Server line identifies the resolver that was queried. If that address is not the DNS server expected for the network, the machine is using a different resolver than assumed, often because a VPN adapter or a manual adapter setting has taken precedence.
What non-authoritative answer means
The phrase Non-authoritative answer means the responding server is not the authoritative source for the zone that contains the name. It is a recursive resolver or a forwarder that obtained the answer from another server and is passing it on. The answer is still an answer; it is simply not marked as coming from the zone’s own name servers.
Authoritative answers appear when nslookup queries a server that hosts the zone directly. For example, querying one of a domain’s own name servers for a name in that domain returns an answer without the non-authoritative label. The distinction matters when diagnosing propagation: a recursive resolver may hold a cached copy of an older record, while the authoritative server holds the current one. Querying both and comparing the results shows whether the record has changed at the source or only in caches.
Querying a specific DNS server
To send the query to a chosen server, put the server address after the name:
nslookup example.com 1.1.1.1
This form is the most useful for comparison. Query the same name against the local resolver, a public resolver, and the zone’s authoritative name server. Differences between the first two indicate caching or forwarding behavior. Differences between either and the authoritative server indicate that the record has changed at the source but has not yet expired from caches.
A server can also be selected interactively:
nslookup
server 1.1.1.1
After the server command, subsequent queries in the same session go to 1.1.1.1 until another server is set. The interactive prompt reports the current default server when it starts.
Record types in interactive mode
By default nslookup asks for A records, and for AAAA records when the query is made over IPv6 or when the resolver returns them. Other record types are requested with the set type command inside interactive mode:
nslookup
set type=MX
example.com
set type=NS
example.com
set type=TXT
example.com
Each set type line changes the query type for the following lookups. set type=ANY requests all types, but many resolvers now refuse or minimize ANY responses, so individual queries are more reliable. The set type setting persists for the session; returning to A records requires set type=A.
MX records show the mail exchangers and their preference values. NS records show the zone’s name servers, which are the addresses to use when an authoritative comparison is needed. TXT records carry SPF, DKIM, and verification strings, and their presence or absence is often the point of the query.
Reverse lookups
A reverse lookup asks for the name associated with an address. nslookup accepts an address directly:
nslookup 203.0.113.20
nslookup converts the address into the in-addr.arpa or ip6.arpa name and queries for a PTR record. A failure here does not mean the forward record is missing; forward and reverse zones are maintained separately, and many addresses have no PTR record at all. The result reflects only what the reverse zone contains.
Resolve-DnsName as the PowerShell alternative
Resolve-DnsName performs the same kind of direct query from PowerShell and returns structured objects rather than formatted text. It is part of the DnsClient module and is available on current Windows versions.
Resolve-DnsName example.com
Resolve-DnsName example.com -Type MX
Resolve-DnsName example.com -Server 1.1.1.1
The -Server parameter selects the DNS server, matching the second argument of nslookup. The -Type parameter selects the record type. Because the output is an object, individual fields can be selected and compared:
Resolve-DnsName example.com -Type A | Select-Object Name, IPAddress, TTL
The TTL field is the remaining cache lifetime in seconds. A low TTL on a recursive resolver’s answer indicates that the cached copy is close to expiry. Comparing TTLs from different resolvers shows how recently each one refreshed its copy.
Resolve-DnsName also exposes the distinction between authoritative and non-authoritative data through its output properties, and it can query a specific record type without entering an interactive session. For scripted comparisons across several servers, it is usually easier to work with than parsing nslookup text.
When nslookup and ping disagree
A disagreement between nslookup and ping is expected whenever the two tools use different resolution paths. The table below separates the common causes by whether they apply to a name that resolves in one tool but not the other.
| Cause | Applies when nslookup and ping disagree | Does not apply when |
|---|---|---|
| Hosts file entry | The name resolves in ping but not nslookup, or to a different address | Both tools return the same address |
| DNS client cache | ping returns an older address after a record change; nslookup shows the new one | The record has not changed recently |
| Different DNS server | nslookup was given an explicit server that differs from the adapter’s configured server | Both queries used the same server |
| Browser DNS-over-HTTPS | The browser resolves a name that fails in nslookup | The browser uses the system resolver |
| Split-horizon DNS | Internal names resolve on the corporate resolver but not on a public one | The name exists only in one view of the zone |
The mechanism behind each row is the same: the tool that produced the result used a different resolver or a different cache. nslookup reports only what the server it queried returned.
Timeouts and server selection
When nslookup reports a timeout, the query reached no server or the server did not answer within the client’s wait period. The default timeout and retry count can be changed in interactive mode:
nslookup
set timeout=5
set retries=2
A timeout against one server but not another points to reachability or to a server that is not listening on port 53. A timeout against every server points to local network configuration, a firewall, or a missing route. Because nslookup sends its own packets, a proxy setting in the browser or a WinHTTP proxy does not affect it; only network-level reachability does.
How nslookup fits with zone structure
The answers nslookup returns are shaped by how DNS zones are delegated. A query for a name in a subdomain may be answered by a different set of name servers than the parent domain, and the NS records returned for the parent show only the delegation, not the subdomain’s own servers. Querying the subdomain’s NS records directly reveals the servers that hold its data. This is why an authoritative comparison should start from the NS records of the exact zone that contains the name, not from the parent.
For the full path a name takes from client to answer, including caching and forwarding, see how DNS resolution works. For the structure of zones and delegations that determine which server is authoritative, see DNS zones explained.
Common questions
Why does nslookup show a different IP than ping?
nslookup queries a DNS server directly and does not read the hosts file or the Windows DNS client cache. ping uses the full Windows resolver, which checks the hosts file and cache first. A hosts file entry or a cached record can therefore make ping return a different address than nslookup.
What does non-authoritative answer mean in nslookup?
It means the server that answered is not the authoritative source for the zone. The server obtained the answer from another server, usually through recursion or forwarding, and is passing it on. The answer is still valid; it is just not marked as coming directly from the zone's own name servers.
How do I query a specific DNS server with nslookup?
Put the server address after the name: nslookup example.com 1.1.1.1. In interactive mode, type server 1.1.1.1 and press Enter, then enter names to query. All subsequent queries in that session go to the selected server until it is changed.
How do I look up MX or TXT records with nslookup?
Start interactive mode by typing nslookup with no arguments, then use set type=MX or set type=TXT before entering the name. The setting persists for the session. Use set type=A to return to address records.
What is the PowerShell equivalent of nslookup?
Resolve-DnsName performs direct DNS queries and returns structured objects. Use -Server to choose a DNS server and -Type to choose a record type, for example Resolve-DnsName example.com -Type MX -Server 1.1.1.1. The output includes TTL and other fields that can be selected and compared.
Read next
- Reading netstat Output: Columns, States and PIDs How to read netstat output: what each column of netstat -ano reports, what LISTENING, ESTABLISHED, TIME_WAIT and CLOSE_WAIT mean, and how to map a PID to a process.
- How DNS Lookup Works: Full Resolution Path Understand the DNS lookup process from stub resolver to authoritative server, including caching at each hop and why changes take time to propagate.
- DNS Scavenging: Why Stale Records Vanish Understand DNS scavenging: how aging and scavenging remove stale records, why records disappear, and how to configure it safely.
- DNS Server Not Responding: Diagnosing Name Resolution Failures Diagnose the 'DNS server not responding' error: distinguish it from NXDOMAIN, test with ping and nslookup, change the DNS server, and flush the cache.
- ERR_CONNECTION_TIMED_OUT: No Answer, Not a Refusal ERR_CONNECTION_TIMED_OUT means the connection attempt got no reply at all. How to tell it from a refusal, test the port with Test-NetConnection, and find the drop.