Nslookup: Complete Guide to DNS Query and Domain Name Troubleshooting Using Kali Linux

Nslookup: Complete Guide to DNS Query and Domain Name Troubleshooting Using Kali Linux

nslookup (Name Server Lookup) is one of the earliest DNS query utilities, predating dig, and is available by default on nearly every operating system including Windows, macOS, and Linux. While it lacks the granular control and scripting-friendly output of dig, its universal availability makes it valuable in constrained environments (e.g., a compromised Windows host during a red team engagement with no additional tools installed) where you need to perform quick DNS reconnaissance using only built-in system utilities.

Installation

nslookup is pre-installed on Kali Linux as part of the dnsutils package (the same package that provides dig).

# Debian/Kali/Ubuntu
sudo apt update && sudo apt install dnsutils -y

# RHEL/CentOS/Fedora
sudo yum install bind-utils -y

Windows and macOS ship with nslookup built into the OS with no installation required.

Verify installation:

nslookup -version

Syntax

nslookup [OPTIONS] [name | -] [server]

Nslookup can run in two modes:

Command-Line Options

Flag/CommandDescription
-type=TYPESpecify the record type to query (A, MX, NS, TXT, SOA, CNAME, PTR, ANY)
-query=TYPEAlias of -type=
-timeout=SECSet the timeout for a reply
-retry=NUMNumber of retries before giving up
-port=PORTUse a non-standard DNS port
-debugTurn on debug output showing full packet details
-d2Exhaustive debug output
-recurseToggle recursive queries on/off (interactive mode)
-vcForce use of a virtual circuit (TCP)
-domain=NAMESet the default domain to append to unqualified names
-srchlist=N1/N2/...Set a custom domain search list
-class=CLASSSet query class (default IN)
serverOptional last argument specifying which DNS server to query
set type=TYPE(interactive) change record type mid-session
set all(interactive) show all current option values
exit(interactive) quit the session

Basic Usage

nslookup example.com

Expected output:

Server:         127.0.0.53
Address:        127.0.0.53#53

Non-authoritative answer:
Name:   example.com
Address: 93.184.216.34

Practical Examples

Example 1 — Basic A record lookup

nslookup example.com
Server:  127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name:    example.com
Address: 93.184.216.34

Example 2 — Query MX records

nslookup -type=MX example.com
example.com     mail exchanger = 10 mail.example.com.

Example 3 — Query using a specific DNS server

nslookup example.com 8.8.8.8
Server:  8.8.8.8
Address: 8.8.8.8#53
Name:    example.com
Address: 93.184.216.34

Example 4 — Reverse lookup

nslookup 8.8.8.8
Server:  127.0.0.53
Address: 127.0.0.53#53
8.8.8.8.in-addr.arpa   name = dns.google.

Example 5 — Query TXT records

nslookup -type=TXT example.com
example.com     text = "v=spf1 -all"

Example 6 — Interactive mode session

nslookup
> server 8.8.8.8
Default server: 8.8.8.8
> set type=NS
> example.com
Server:  8.8.8.8
Address: 8.8.8.8#53
example.com     nameserver = a.iana-servers.net.
example.com     nameserver = b.iana-servers.net.
> exit

Example 7 — Query with debug output for troubleshooting

nslookup -debug example.com
------------
    QUESTIONS:
        example.com, type = A, class = IN
    ANSWERS:
    ->  example.com
        internet address = 93.184.216.34
        ttl = 86400
------------

Common Use Cases

Automation with Bash

Batch reverse-lookup a list of IPs:

#!/bin/bash
# reverse_lookup.sh
while IFS= read -r ip; do
    echo "=== $ip ==="
    nslookup "$ip" | grep "name ="
done < ip_list.txt

Query multiple record types for a domain:

#!/bin/bash
DOMAIN=$1
for TYPE in A MX NS TXT; do
    echo "--- $TYPE ---"
    nslookup -type=$TYPE "$DOMAIN"
    echo
done

Tips and Best Practices

Troubleshooting

ProblemCauseFix
** server can't find example.com: NXDOMAINDomain does not exist or typo in domain nameVerify domain spelling; check registration status with whois
; connection timed out; no servers could be reachedFirewall blocking DNS traffic outboundTry a different network or explicitly specify a reachable server
Output shows “Non-authoritative answer”Response came from a caching resolver, not the authoritative serverQuery the authoritative name server directly for a canonical answer
-type=ANY returns minimal/empty responseRFC 8482 compliance — many resolvers no longer return full ANY responsesQuery specific record types individually (A, MX, TXT, NS) instead

References

Exit mobile version