Loading date…
Gear We Use:
SATURDAY
00 : 00 : 00
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Linux nslookup Cheat Sheet: How SOC Analysts Investigate DNS

Diagram showing Linux nslookup DNS queries comparing local resolv.conf resolvers and public DNS across A, MX, TXT, PTR, and DMARC records.

Last verified: November 28, 2026

Quick Answer
The Linux nslookup command queries DNS servers to inspect A, MX, NS, TXT, PTR, and DMARC records during SOC triage. Because it bypasses /etc/hosts and has parser quirks, verify critical DNSSEC or automation workflows with dig.

During an active alert triage on a Linux jump host, an endpoint connection to an unfamiliar domain rarely tells the full story on its own. An analyst needs to confirm whether the local resolver differs from public DNS, whether email authentication policies are intact, or whether a suspicious domain resolves through a Protective DNS sinkhole or a Content Delivery Network.

Sponsored
root@kali:~# lsusb
Best Adapters for Kali Linux
Wi-Fi adapters for your pentesting lab
Shop Now →
As an Amazon Associate, I earn from qualifying purchases. This costs you nothing extra.

Although newer diagnostic tools exist, nslookup remains widely available across enterprise Linux systems, container jump boxes, and cross-platform incident-response playbooks. This cheat sheet organizes nslookup commands for defensive DNS investigation, email security verification, troubleshooting, and safe shell automation while highlighting the operational edge cases that commonly trip up responders.

How Does nslookup Work on Linux During SOC Triage?

The Linux nslookup command is a command-line DNS diagnostic utility included in the ISC BIND bind9-dnsutils and bind-utils packages that queries name servers directly via /etc/resolv.conf. According to the ISC BIND 9 manual, it supports non-interactive single lookups and interactive troubleshooting while bypassing local /etc/hosts entries.

This Name Service Switch (NSS) bypass matters during host-level forensics. If malware or an administrator modified /etc/hosts, tools such as ping and curl may connect to the overridden IP, whereas nslookup continues querying the DNS server listed in /etc/resolv.conf (frequently the local systemd-resolved stub at 127.0.0.53 on modern distributions).

Basic Non-Interactive DNS Lookups

# Resolve domain using the system-configured DNS resolver
nslookup example.com

# Enter interactive mode and display default resolver details
nslookup

# Query using public recursive resolvers (Google, Cloudflare, Quad9)
nslookup example.com 8.8.8.8
nslookup example.com 1.1.1.1
nslookup example.com 9.9.9.9

# Reverse DNS lookup for an IPv4 address
nslookup 8.8.8.8

# Explicit IPv4 (A) and IPv6 (AAAA) record lookups
nslookup -type=A example.com
nslookup -type=AAAA example.com
  • What it does: Runs single-shot forward or reverse lookups against either the host's configured resolver or a specified target DNS server IP.
  • When to use it: During initial alert triage to verify whether a domain resolves to IPv4 (A) or IPv6 (AAAA) addresses and whether public resolvers agree with internal DNS.
  • Expected output and caveats: Outputs the queried server IP/port first, followed by Name: and Address: blocks. Unprivileged users can run all lookups safely. On hosts running systemd-resolved, the server line often displays 127.0.0.53 instead of the upstream corporate resolver.

Which DNS Record Types Should SOC Analysts Query with nslookup?

DNS resource record queries in nslookup use the -type= option to retrieve specific infrastructure mappings, including IPv4 (A), IPv6 (AAAA), mail routing (MX), name servers (NS), zone authority (SOA), text policies (TXT), aliases (CNAME), certificate authorizations (CAA), and DNSSEC keys. Per IETF RFC 8482, ANY queries often return minimal responses rather than full zone records.

Understanding which record types reveal operational dependencies helps defenders spot fast-changing hosting, unauthorized mail relays, and shadow SaaS integrations without running noisy port scans against external infrastructure.

Record Type Command Syntax Primary Defensive Use Operational Caveat
A nslookup -type=A example.com Maps domain to IPv4 addresses CDN domains rotate multiple edge IPs rapidly
AAAA nslookup -type=AAAA example.com Maps domain to IPv6 addresses Missed if triage checks IPv4 telemetry only
MX nslookup -type=MX example.com Identifies inbound mail servers and priority Outbound mail senders may differ (check SPF)
NS nslookup -type=NS example.com Identifies authoritative DNS providers Registrar-level changes take time to propagate
SOA nslookup -type=SOA example.com Shows primary name server, contact, and serial Useful for tracking recent zone modifications
TXT nslookup -type=TXT example.com Audits SPF, DMARC, DKIM, and verification tokens SaaS verification strings reveal third-party tools
CNAME nslookup -type=CNAME www.example.com Exposes alias targets and cloud origins Dangling aliases risk subdomain takeover
PTR nslookup -type=PTR 8.8.8.8 Resolves IP back to canonical hostname Many cloud/ISP IPs lack custom PTR records
SRV nslookup -type=SRV _sip._tcp.example.com Discovers service ports/hosts (SIP, LDAP, Kerberos) Must include exact service and protocol prefix
CAA nslookup -type=CAA example.com Lists authorized TLS Certificate Authorities Missing CAA permits any trusted CA to issue certs
DNSKEY nslookup -type=DNSKEY example.com Fetches DNSSEC public signing keys Server support varies; no validation chain check
DS nslookup -type=DS example.com Inspects parent-zone Delegation Signer hash Use dig or delv for full DNSSEC verification
ANY nslookup -type=ANY example.com Requests multiple cached record types Blocked or minimized per RFC 8482; incomplete
# Standard infrastructure records
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=TXT example.com
nslookup -type=CNAME www.example.com

# Reverse, service, certificate, and DNSSEC records
nslookup -type=PTR 8.8.8.8
nslookup -type=SRV _sip._tcp.example.com
nslookup -type=CAA example.com
nslookup -type=DNSKEY example.com
nslookup -type=DS example.com
nslookup -type=ANY example.com
  • What it does: Queries individual DNS resource record types for the target hostname or IP address using the -type= flag (alias of -querytype=).
  • When to use it: Whenever enriching domain observables beyond simple IP mapping—especially checking CNAME targets for cloud hosting, SRV records in Active Directory/VoIP audits, or CAA policies during TLS certificate reviews.
  • Expected output and caveats: Returns matching records or Can't find ...: No answer if the domain exists but lacks that record type. Do not rely on -type=ANY to audit a domain; authoritative servers frequently return a single synthetic HINFO record or subset to prevent amplification abuse. Likewise, use dig +dnssec rather than nslookup when validating DNSSEC signatures.

How Do You Perform Reverse DNS Lookups and Query Specific Resolvers?

Reverse DNS lookups in nslookup query Pointer (PTR) records across the .in-addr.arpa and .ip6.arpa namespaces to map IPv4 or IPv6 addresses back to hostnames. Appending a resolver IP such as 8.8.8.8, 1.1.1.1, or 9.9.9.9 bypasses the local resolver to expose split-horizon DNS or Protective DNS filtering differences.

Reverse DNS Lookups for IPv4 and IPv6

# Shorthand IPv4 reverse DNS lookups
nslookup 8.8.8.8
nslookup 1.1.1.1

# Reverse lookup for an RFC 5737 documentation IP
nslookup 203.0.113.10

# Reverse lookup for an IPv6 address (automatically mapped to .ip6.arpa)
nslookup 2001:4860:4860::8888

# Explicit PTR record syntax
nslookup -type=PTR 8.8.8.8
  • What it does: Translates an IPv4 or IPv6 address into its corresponding reverse-lookup domain and fetches the PTR hostname record.
  • When to use it: When triaging unfamiliar destination IPs in firewall, NetFlow, or proxy logs to identify ISP ownership, cloud provider infrastructure, or mail relay hostnames.
  • Expected output and caveats: Public DNS servers typically return entries such as dns.google or one.one.one.one. Example addresses from IETF RFC 5737 (such as 203.0.113.10 in TEST-NET-3) return NXDOMAIN because they are reserved for documentation. Crucially, a missing PTR record is common across cloud virtual machines and does not indicate malicious intent, nor does a benign-looking PTR string prove trustworthiness without forward-confirmed reverse DNS (FCrDNS).

Specifying External or Internal Resolvers

# Basic resolution against public resolvers
nslookup example.com 8.8.8.8
nslookup example.com 1.1.1.1
nslookup example.com 9.9.9.9

# Combine specific record types with custom resolvers
nslookup -type=MX example.com 8.8.8.8
nslookup -type=TXT example.com 1.1.1.1
nslookup -type=NS example.com 8.8.8.8
nslookup -type=SOA example.com 1.1.1.1
  • What it does: Overrides /etc/resolv.conf for a single command by directing the query to the specified resolver IP.
  • When to use it: When confirming whether a local resolver is blocking a domain (Protective DNS/RPZ sinkhole), caching stale records after a DNS change, or serving internal-only split-DNS answers.
  • Expected output and caveats: OPSEC warning: Never send confidential internal hostnames or unique phishing-link tracking subdomains to third-party public resolvers (8.8.8.8, 1.1.1.1, 9.9.9.9). Doing so exposes internal naming conventions externally and can alert an adversary monitoring authoritative query logs.

How Do You Use nslookup Interactive Mode and Debug Options?

Interactive mode in nslookup is a stateful shell session launched without domain arguments that lets analysts switch resolvers, change record types, toggle recursion, force TCP virtual circuits (set vc), adjust timeouts, and inspect raw DNS packets using set debug or exhaustive set d2 tracing without retyping base command syntax.

Interactive Session Commands and Record Switching

# Start an interactive nslookup session
nslookup

# Commands entered at the interactive prompt:
> example.com
> server 8.8.8.8
> server 1.1.1.1
> set type=A
> set type=AAAA
> set type=MX
> set type=NS
> set type=TXT
> set type=SOA
> set type=CNAME
> set type=ANY
> set type=PTR
> example.com
> set type=MX
> example.com
> set type=NS
> example.com
> set type=TXT
> example.com
> set type=A
> example.com
> exit
  • What it does: Opens an interactive shell where server changes the active resolver and set type= persists across subsequent domain queries until altered or exited.
  • When to use it: When inspecting multiple record types across the same domain or pivoting iteratively between internal and external resolvers during an investigation.
  • Expected output and caveats: Prints the active server and requested records after each domain entry. Remember that changing set type= stays active for all following queries in that session; run set all at the prompt anytime to verify your active settings before trusting an unexpected empty response.

Advanced Debugging, TCP Virtual Circuits, and Timeout Flags

# Interactive configuration tuning and packet debugging
nslookup
> set all
> set debug
> set nodebug
> set d2
> set nod2
> set recurse
> set norecurse
> set vc
> set novc
> set timeout=5
> set retry=2
> set port=53
> set type=MX
> example.com
> exit

# Equivalent non-interactive CLI options
nslookup -debug example.com
nslookup -debug -type=MX example.com
nslookup -vc example.com
nslookup -timeout=5 example.com
nslookup -retry=2 example.com
  • What it does: Configures transport behavior (UDP vs. TCP virtual circuits via vc), recursion flags (RD bit), query timeouts, retry counts, target ports, and verbose packet-header/answer dumps (debug and d2).
  • When to use it: Use -debug or set d2 to inspect Time-to-Live (TTL) values, query flags, and truncated packet headers; use -vc to test whether oversized responses (such as large TXT/DNSSEC payloads) fail over UDP 53 or are blocked on TCP 53.
  • Expected output and caveats: -debug displays HEADER, QUESTIONS, ANSWERS, AUTHORITY RECORDS, and ADDITIONAL RECORDS sections, including exact TTLs in seconds. Note that CLI flags such as -timeout and -retry vary slightly across OS ports and BIND builds; interactive set options provide consistent control across platforms.

How Can You Audit SPF, DKIM, DMARC, and CAA Records with nslookup?

Email authentication auditing with nslookup verifies Sender Policy Framework (RFC 7208), Domain-based Message Authentication, Reporting, and Conformance (RFC 7489), DKIM public keys, and Certification Authority Authorization (RFC 8659) DNS records. Aligned with CISA BOD 18-01, these lookups help defenders evaluate spoofing exposure.

# 1. Inspect mail exchange servers
nslookup -type=MX example.com

# 2. Check SPF policy in apex TXT records
nslookup -type=TXT example.com

# 3. Check DMARC enforcement policy and reporting URI
nslookup -type=TXT _dmarc.example.com

# 4. Query DKIM public key using an observed header selector
nslookup -type=TXT selector1._domainkey.example.com

# 5. Confirm authoritative name servers, SOA, and TLS CAA controls
nslookup -type=NS example.com
nslookup -type=SOA example.com
nslookup -type=CAA example.com
  1. Inspect MX and SPF records: Confirm mail exchangers belong to expected providers and examine the v=spf1 string for unauthorized include: directives, excessive DNS lookups (limit is 10 per RFC 7208), or permissive +all / ?all mechanisms instead of -all or ~all.
  2. Validate _dmarc policy enforcement: Verify whether v=DMARC1 sets p=reject or p=quarantine rather than monitor-only p=none, and confirm rua= aggregate reporting targets an authorized mailbox.
  3. Verify DKIM using the message selector: Unlike SPF and DMARC, DKIM keys reside under <selector>._domainkey.<domain>. Extract the exact selector from the s= tag inside the suspicious email's DKIM-Signature header (for example, selector1 or google) before querying.
  4. Audit CAA records: Confirm CAA entries restrict certificate issuance (issue and issuewild tags) to approved Certificate Authorities, reducing unauthorized certificate issuance risk for lookalike or delegated subdomains.

Expected output and caveats: Healthy domains return quoted text = "v=spf1 ..." and text = "v=DMARC1; ..." lines. Note that valid SPF and DMARC records only verify domain-policy configuration; compromised third-party SaaS senders or lookalike domains registered by an attacker can still pass their own SPF, DKIM, and DMARC checks.

How Do SOC Analysts Use nslookup for Threat Hunting and DNS Troubleshooting?

Defensive threat hunting with nslookup maps suspicious domain infrastructure against external resolvers, supporting triage for MITRE ATT&CK T1590.002 and T1071.004 investigations. During outage troubleshooting, comparing internal resolvers with 8.8.8.8, forcing TCP queries, and adjusting query timeouts quickly isolates blocked UDP ports and stale caches.

Suspicious Domain Enrichment Triage Workflow

The commands below use RFC 2606 reserved .example domains and RFC 5737 documentation IPs; substitute the actual external indicator observed in your SIEM or EDR telemetry.

# Core forward and alias resolution (replace with observed external indicator)
nslookup suspicious-domain.example
nslookup -type=A suspicious-domain.example
nslookup -type=AAAA suspicious-domain.example
nslookup -type=CNAME suspicious-domain.example

# Infrastructure and policy footprinting
nslookup -type=MX suspicious-domain.example
nslookup -type=NS suspicious-domain.example
nslookup -type=TXT suspicious-domain.example
nslookup -type=SOA suspicious-domain.example

# Reverse lookup on an observed destination IP (RFC 5737 placeholder)
nslookup 203.0.113.25

# Compare internal resolver output against external recursive resolvers
nslookup suspicious-domain.example 8.8.8.8
nslookup suspicious-domain.example 1.1.1.1
  • What it does: Collects the full public DNS footprint of a suspect domain—resolving IPs, alias chains, name servers, mail servers, and verification TXT entries—while cross-checking internal vs. external resolution.
  • When to use it: During phishing triage, outbound beacon alerts, or threat intelligence enrichment when confirming whether a domain is actively resolving, parked, sinkholed by internal Protective DNS, or newly delegated.
  • Expected output and caveats: If your internal resolver returns a sinkhole IP (or NXDOMAIN via RPZ policy) while 8.8.8.8 returns a live hosting IP, internal DNS controls likely intercepted the lookup. Conversely, identical CDN IPs across both resolvers do not establish legitimacy or malice on their own, as legitimate and malicious sites frequently share cloud reverse proxies.

Troubleshooting DNS Resolution Failures

# Baseline internal lookup vs. external public resolvers
nslookup example.com
nslookup example.com 8.8.8.8
nslookup example.com 1.1.1.1

# Verify delegation and zone metadata
nslookup -type=NS example.com
nslookup -type=SOA example.com

# Inspect packet headers, force TCP, and raise query timeout
nslookup -debug example.com
nslookup -vc example.com
nslookup -timeout=10 example.com
  • What it does: Systematically separates local resolver faults from upstream delegation issues, firewall UDP/TCP port 53 restrictions, and high-latency paths.
  • When to use it: When applications report intermittent name resolution failures, log ingestion stalls after a domain migration, or large DNS responses fail on restrictive corporate firewalls.
  • Expected output and caveats: If standard queries time out while -vc succeeds, inspect network ACLs or MTU fragmentation affecting UDP 53 traffic. If -timeout=10 succeeds where defaults fail, investigate upstream latency or overloaded internal forwarders.

What Do nslookup Response Codes and Status Messages Mean?

DNS response messages in nslookup indicate whether an answer came from a recursive cache (Non-authoritative answer) or a domain's owning server (Authoritative answer), alongside status codes like NXDOMAIN, SERVFAIL, REFUSED, and No answer. Misreading these labels often leads junior analysts to mistake routine caching or Protective DNS blocks for server failures.

Response Term / Code Protocol Meaning Typical Cause SOC Triage Interpretation
Name Canonical domain or alias target resolved Matches queried host or final CNAME destination Watch for unexpected CNAME redirects to third-party hosts
Address Returned IPv4/IPv6 endpoint or resolver IP First block shows DNS server; lower block shows answer Avoid confusing the resolver's IP at the top with the target IP
Non-authoritative answer Response served from a recursive resolver cache Standard caching on ISP, corporate, or public resolvers Normal behavior; not an indicator of spoofing or tampering
Authoritative answer Response came directly from the zone's owning server Query sent directly to an authoritative NS for the domain Confirmed live zone state bypassing recursive cache TTLs
NXDOMAIN Non-Existent Domain (domain does not exist) Unregistered/expired domain, typo, DGA, or RPZ block High volume of NXDOMAIN queries can indicate DGA activity or misconfigured apps
SERVFAIL Server failed to complete the DNS query Broken delegation, DNSSEC validation failure, or dead upstream Check DNSSEC health with dig or test another resolver
REFUSED Target name server declined to answer ACL restriction, disabled recursion, or rate limiting Expected when querying an external server that disallows open recursion
No answer Domain exists, but requested RR type is absent Querying MX or AAAA on an IPv4-only hostname Confirms domain existence without that specific service record

How Do You Automate Bulk Lookups Safely (and When to Switch to dig)?

Batch execution in nslookup uses shell redirection, standard input command files, and POSIX loops to query multiple domains or record types sequentially. However, the ISC BIND 9 manual recommends dig for DNS troubleshooting and scripting because nslookup has inconsistent output formatting and lacks full DNSSEC validation output.

# Save and append single lookup results to a text file
nslookup -type=A example.com
nslookup -type=A example.com 8.8.8.8
nslookup example.com > dns-output.txt
nslookup -type=MX example.com >> dns-output.txt

# Feed a pre-built batch command file via standard input
nslookup < dns-commands.txt

# Example contents of dns-commands.txt:
# server 8.8.8.8
# set type=A
# example.com
# set type=MX
# example.com
# exit

# Loop over a list of domains in domains.txt
while read -r domain; do
  echo "===== $domain ====="
  nslookup "$domain"
done < domains.txt

# Enumerate multiple record types for a single domain
for type in A AAAA MX NS TXT SOA CAA; do
  echo "===== $type ====="
  nslookup -type="$type" example.com
done
  • What it does: Automates multi-domain or multi-record checks and writes human-readable output into triage logs.
  • When to use it: Useful for quick ad-hoc evidence capture during an incident when dig or Python DNS libraries are unavailable on a minimal jump host.
  • Expected output and caveats: Produces sequential text sections separated by banner headers. For production SOAR playbooks or CI/CD checks, avoid scraping nslookup output: exit codes vary across older implementations on NXDOMAIN, and multi-line output breaks easily. Prefer dig +short, dig +trace, delv (for DNSSEC validation), or Python's dnspython, and add throttling (sleep) when running large lists to avoid triggering resolver rate limits.
Sponsored
root@kali:~# lsusb
Best Adapters for Kali Linux
Wi-Fi adapters for your pentesting lab
Shop Now →
As an Amazon Associate, I earn from qualifying purchases. This costs you nothing extra.

Key Operational Guardrails for Defensive DNS Lookups

  1. Do not rely on ANY for full inventories: Under RFC 8482, servers routinely truncate or substitute ANY responses; query each required record type explicitly.
  2. Treat nslookup as a point lookup tool, not zone enumeration: nslookup cannot reliably enumerate hidden subdomains; authorized external asset discovery relies on zone-file audits or passive DNS telemetry.
  3. Account for caching, split DNS, GeoDNS, and RPZ filtering: Differences between your corporate resolver, 8.8.8.8, and 1.1.1.1 often reflect TTL expiration, geographic CDN steering, split-horizon zones, or Protective DNS policies.
  4. Do not flag Non-authoritative answer as anomalous: Nearly all recursive resolver lookups return cached answers unless you query an authoritative name server directly.
  5. Avoid judging malice from missing PTR records or single IPs: Missing reverse DNS is normal for dynamic/cloud endpoints, and DNS resolution alone never confirms whether a domain is malicious or benign without passive DNS, HTTP, TLS, and endpoint context.
  6. Use dig for DNSSEC and delegation tracing: Switch to dig +dnssec or dig +trace whenever debugging broken chains of trust, inspecting AD flags, or parsing results in scripts.
  7. Stay strictly within authorized scope and protect internal names: Perform active reconnaissance only against authorized assets, and never send sensitive internal hostnames to public third-party DNS resolvers.

Frequently Asked Questions

Does nslookup read /etc/hosts on Linux?

No. Unlike utilities such as ping, curl, or ssh that use the Linux Name Service Switch (/etc/nsswitch.conf), nslookup queries the DNS servers listed in /etc/resolv.conf directly and ignores static entries in /etc/hosts.

Why does nslookup -type=ANY only return an HINFO or partial response?

Many authoritative name servers and public recursive resolvers implement IETF RFC 8482, which permits returning a minimal synthetic HINFO record or single record subset for ANY queries to reduce DNS amplification DDoS risk. Query individual types such as A, AAAA, MX, NS, and TXT instead.

Is a "Non-authoritative answer" in nslookup a sign of DNS spoofing?

No. A Non-authoritative answer simply means the recursive resolver (such as your corporate DNS server, 127.0.0.53, or 8.8.8.8) returned a cached record rather than fetching it directly from the domain's authoritative name server.

How do I check DKIM records with nslookup if I do not know the selector?

You cannot list unknown DKIM selectors with a generic nslookup query because DKIM public keys live at <selector>._domainkey.<domain>. Inspect the s= parameter in a captured email's DKIM-Signature header (or email gateway logs) to find the active selector first.

Why does nslookup work on 8.8.8.8 but return NXDOMAIN or a different IP internally?

This discrepancy usually indicates split-horizon DNS (different internal vs. public zone views), stale internal resolver caching, geographic CDN routing, or an internal Protective DNS / Response Policy Zone (RPZ) rule blocking or sinkholing the domain.

Should SOC analysts use nslookup or dig on Linux?

Use nslookup for fast interactive checks or cross-platform playbooks where it is guaranteed to be installed, and prefer dig whenever you need parseable script output, full delegation path tracing (+trace), or DNSSEC validation flags (+dnssec).

Conclusion

Mastering nslookup gives Linux administrators and SOC analysts a fast, cross-platform baseline for forward and reverse DNS lookups, resolver comparisons, email authentication audits, and packet-level debugging. Pairing these commands with awareness of /etc/hosts bypass behavior, RFC 8482 ANY limits, internal-hostname OPSEC, and dig escalation ensures accurate triage without false-positive conclusions.

Analysis based on public ISC BIND documentation, IETF DNS standards, CISA guidance, MITRE ATT&CK references, and defensive SOC engineering review.

Shubham Chaudhary

Shubham Chaudhary is a cybersecurity specialist and founder of Xpert4Cyber. He shares practical tutorials, guides and the latest news on Networking, Windows Server, Linux Server, Ethical Hacking, Digital Forensics, Malware Analysis, Threat Hunting and Monitoring, OSINT, Cloud Computing and AI, with a focus on defense and security awareness. Educational and defensive use only.

Post a Comment

Previous Post Next Post
ADVERTISEMENT
ADVERTISEMENT