VMware ESXi and vSphere Cluster Management

How to Use the nslookup Command for DNS Lookups in Linux

Learn how to use nslookup in Linux for forward and reverse DNS lookups, MX, NS, SOA, TXT, CNAME, and other DNS records.

nslookup is a command-line utility for querying DNS servers. DNS, the Domain Name System, maps names such as www.example.com to information such as IP addresses, mail servers, and nameservers.

This guide covers interactive and non-interactive lookups, common DNS record types, resolver selection, output interpretation, troubleshooting, and safer alternatives such as dig and host.

What nslookup Does

A DNS lookup asks a DNS server for records associated with a hostname, domain, or IP address. A forward lookup maps a name to an address or another DNS record. A reverse lookup maps an IP address to a hostname through a PTR record.

nslookup www.example.com
nslookup 8.8.8.8

The first command performs a forward lookup. The second asks whether the owner of 8.8.8.8 has published a reverse DNS name. Results depend on the DNS server queried, its cache and policy, and the records published for the target.

Common DNS Record Types

A DNS record is a piece of data stored in a DNS zone, which is a managed portion of the DNS namespace.

Query typeTypical command formWhat it returnsCommon use case
Anslookup -type=a example.comIPv4 addressCheck IPv4 resolution
AAAAnslookup -type=aaaa example.comIPv6 addressCheck IPv6 resolution
PTRnslookup -type=ptr 8.8.8.8Reverse mapping from an IP to a nameInspect reverse DNS
MXnslookup -type=mx example.comMail servers and preference valuesDiagnose mail delivery
NSnslookup -type=ns example.comNameservers for a zoneInspect delegation
SOAnslookup -type=soa example.comZone authority and timing metadataCompare zone versions and timing
CNAMEnslookup -type=cname www.example.comAlias to a canonical nameInvestigate DNS aliases
TXTnslookup -type=txt example.comText stringsCheck verification and email policy data
ANYnslookup -type=any example.comA server-selected set of available dataOccasional diagnostic testing

An A record contains an IPv4 address, while an AAAA record contains an IPv6 address. A domain can have multiple records of either type, so a lookup can return multiple addresses.

A CNAME is an alias pointing to another, canonical name. Output may show the canonical name before showing the final A or AAAA addresses.

MX records identify mail exchangers. Their preference values are ordered numerically: a lower value means higher delivery priority. NS records identify nameservers responsible for a DNS zone.

An SOA record includes the primary nameserver, a responsible-party field, a serial number, refresh interval, retry interval, expire interval, and a minimum value commonly associated with negative caching. The serial number is useful when checking whether authoritative servers have the same zone version.

TXT records carry text data and are commonly used for domain verification, SPF-related data, DKIM-related information, and other policies. An ANY query is not a reliable request for every record. Modern DNS servers often minimize or restrict ANY responses, so query each required type separately.

Interactive Mode

Run nslookup without a target to enter its interactive prompt.

$ nslookup
>

Enter a hostname to request address information:

> www.example.com

Enter an IP address to request a PTR-based reverse lookup:

> 8.8.8.8

Set a record type with either set type= or set q=:

> set type=mx
> example.com
> set q=ns
> example.com

Change the DNS server used for later queries with server:

> server 1.1.1.1
> www.example.com

Check the displayed server information before interpreting the answer. Leave the session with exit.

> exit

Non-Interactive Mode

Non-interactive mode is useful for one-off commands, scripts, and quick checks. The general form is:

nslookup [options] target [dns-server]

Perform a forward lookup from the shell:

nslookup www.example.com

Perform a reverse lookup:

nslookup 8.8.8.8

Request a particular record type with -type=:

nslookup -type=a example.com
nslookup -type=aaaa example.com
nslookup -type=mx example.com
nslookup -type=ns example.com
nslookup -type=soa example.com
nslookup -type=cname www.example.com
nslookup -type=txt example.com

Some implementations also support the equivalent -query= spelling:

nslookup -query=mx example.com

For a single command, place the DNS server after the target:

nslookup www.example.com 1.1.1.1

The final argument can identify a recursive resolver or, when appropriate, an authoritative nameserver.

Forward Lookup Examples

To resolve a hostname to address data, use:

nslookup www.example.com

Inspect the returned A and AAAA information. Multiple addresses are normal and may support redundancy, load distribution, geographic routing, or separate IPv4 and IPv6 access.

If the output includes an alias or canonical name, follow that name when diagnosing the final address. A CNAME does not itself contain an IP address; it points the resolver to another name whose address records can then be returned.

Reverse Lookup Examples

Use an IP address as the target:

nslookup 8.8.8.8

A successful reverse lookup displays a PTR name when one is published. Reverse DNS is optional, so an IP address can be valid and reachable even when it has no PTR record.

Reverse DNS is managed through the owner of the relevant reverse-DNS space, normally the organization controlling the IP allocation or the hosting provider. It is not usually controlled through the ordinary forward DNS zone for a domain.

Mail, Delegation, and Zone Authority Lookups

MX records

nslookup -type=mx example.com

Read each mail exchanger and its preference. Mail systems generally try lower preference values before higher ones, although delivery behavior also depends on the sender and mail server implementation.

NS records

nslookup -type=ns example.com

NS records show the nameservers listed for the domain's zone. They are a useful starting point when checking delegation or deciding which authoritative servers to query next.

SOA records

nslookup -type=soa example.com

Use the SOA result to inspect the primary nameserver, responsible-party field, serial number, refresh, retry, expire, and minimum or negative-caching-related value. Comparing serial numbers across authoritative nameservers can reveal incomplete zone updates.

Choosing Which DNS Server to Query

With no explicit server, nslookup normally uses the resolver configured for the Linux system. That resolver may be supplied by network configuration, a VPN, a local resolver service, or a resolver manager.

To compare the system resolver with a named resolver, run:

nslookup www.example.com
nslookup www.example.com 1.1.1.1

Answers can differ because of:

  • Split-horizon DNS: internal and external clients receive different answers.
  • Caching: resolvers may hold older data until its TTL, or time to live, expires.
  • Filtering: a resolver may block, redirect, or alter selected responses.
  • Propagation state: recent changes may not be visible through every cache or authoritative server.
  • Resolver policy: geographic, organizational, or security rules may affect the answer.

A public resolver is not a substitute for a private organizational resolver. Internal-only names may exist only inside a corporate, cloud, or VPN DNS environment.

Understanding nslookup Output

Typical output identifies the DNS server used and its address. It may then show a name, aliases, addresses, or record-specific values such as MX preferences and SOA fields.

A non-authoritative answer usually came from a recursive resolver, which obtained the data on behalf of the client and may have served it from cache. An authoritative answer came from a server publishing the official data for the zone. Non-authoritative does not mean incorrect; it describes the source of the response.

Output formatting varies between Linux distributions, operating systems, and nslookup implementations. Read the values rather than relying on exact wording or column layout.

Observed resultLikely meaningSuggested next check
Address returnedThe requested name has an address record visible to this resolver.Check both A and AAAA if IPv4 and IPv6 behavior matters.
Non-authoritative answerA recursive resolver returned the response, possibly from cache.Check TTL or compare with an authoritative nameserver.
NXDOMAINThe queried domain name does not exist from that DNS server's perspective.Check spelling, the fully qualified name, and the intended DNS environment.
SERVFAILThe server could not complete the query, often because of an upstream, DNSSEC, or configuration problem.Try another resolver and inspect authoritative-server health.
TimeoutNo response arrived before the client timeout.Check connectivity, firewall rules, VPN state, and resolver availability.
No PTR resultNo reverse-DNS name is published or visible.Check with the IP address provider or hosting provider.
Different answers from different resolversPolicy, caching, split-horizon DNS, geographic routing, or an update difference may exist.Record the resolver used and compare authoritative responses.

Troubleshooting nslookup

Command not found

If the shell reports that nslookup is missing, the DNS utilities package may not be installed. Identify the package that provides DNS client tools for your distribution and install it with the system package manager. If available, dig or host can be used instead.

NXDOMAIN

Verify spelling and the intended fully qualified domain name. For a private name, query the organization's internal resolver rather than a public resolver. If you manage the domain, inspect the authoritative zone configuration.

Timeouts

Check configured resolvers, network connectivity, and whether UDP or TCP port 53 is blocked. For internal names, confirm that the VPN and internal firewall path are working. Test a different resolver only when doing so is appropriate for the name and your organization's policy.

Missing PTR data

A missing PTR record is a DNS configuration condition, not proof that the IP address is invalid. Contact the address provider or use its reverse-DNS control panel if you are authorized to make the change.

Inconsistent answers

Document the resolver used for every test. Compare internal and external resolvers, query authoritative nameservers when appropriate, and review TTLs and deployment timing.

Incomplete ANY results

Do not interpret an incomplete ANY response as proof that other records are absent. Query A, AAAA, MX, NS, SOA, TXT, and other required types individually.

Limitations and Modern Alternatives

nslookup remains common in tutorials, enterprise environments, and cross-platform troubleshooting, but it is a legacy-oriented utility. It may not be installed by default, and options and output can differ between implementations.

  • dig example.com provides detailed DNS diagnostics, explicit server selection, response flags, TTLs, and machine-friendly controls.
  • host example.com provides concise output for common forward and reverse queries.

Use nslookup when you need a familiar, widely available interface; choose dig when precise DNS troubleshooting or scripting control is important.

Security and Privacy Considerations

A DNS lookup discloses the queried name to the resolver handling the request. Public DNS services should not be treated as equivalent to private internal resolvers.

  • Avoid sending internal-only hostnames, service names, customer names, or sensitive investigation targets to external resolvers.
  • Use the approved organizational or VPN resolver for private infrastructure.
  • Record which resolver was used when collecting diagnostic evidence.
  • Remember that a public answer may describe public DNS and not the address visible inside a private network.

Interactive and Non-Interactive Modes

ModeHow to start itBest useExampleKey limitations
Interactive modenslookupSeveral related queries with one server and sessionset type=mx, then example.comEasy to make state mistakes; output and commands vary by implementation
Non-interactive modenslookup targetOne-off checks and simple command usenslookup -type=soa example.comLess convenient for many record types in one session

Practical Command Checklist

  1. Start with nslookup hostname for a normal forward lookup.
  2. Check -type=a and -type=aaaa when address-family behavior matters.
  3. Use an IP address as the target to test reverse DNS.
  4. Use -type=mx, -type=ns, or -type=soa for mail, delegation, and zone-authority checks.
  5. Use -type=txt for verification and policy data.
  6. Repeat the lookup against a named resolver when comparing DNS views.
  7. Use dig for detailed diagnostics and host for concise output.