Nslookup - DNS Lookup and Troubleshooting
Overview
nslookup is a network administration command-line tool for querying the Domain Name System (DNS) to obtain domain name or IP address mapping, or other DNS records. It's available on most operating systems and is essential for DNS troubleshooting and network diagnostics.
Basic Syntax
# Non-interactive mode
nslookup [ options] [ name] [ server]
# Interactive mode
nslookup
nslookup -
nslookup - [ server]
Essential Commands
Basic DNS Lookups
# Look up A record (IPv4 address)
nslookup google.com
``
``Copy
# Look up using specific DNS server
nslookup google.com 8 .8.8.8
``
``Copy
# Reverse DNS lookup (IP to domain)
nslookup 8 .8.8.8
``
``Copy
Record Type Queries
# A record (IPv4 address)
nslookup -type= A google.com
``
``Copy
# AAAA record (IPv6 address)
nslookup -type= AAAA google.com
``
``Copy
# MX record (Mail Exchange)
nslookup -type= MX google.com
``
``Copy
# NS record (Name Server)
nslookup -type= NS google.com
``
``Copy
# TXT record (Text records)
nslookup -type= TXT google.com
``
``Copy
# CNAME record (Canonical Name)
nslookup -type= CNAME www.google.com
``
``Copy
# SOA record (Start of Authority)
nslookup -type= SOA google.com
``
``Copy
# PTR record (Pointer for reverse lookup)
nslookup -type= PTR 8 .8.8.8
``
``Copy
# ANY record (All available records)
nslookup -type= ANY google.com
``
``Copy
# SRV record (Service record)
nslookup -type= SRV _sip._tcp.example.com
``
``Copy
Interactive Mode
Starting Interactive Mode
# Enter interactive mode
nslookup
``
``Copy
# Enter interactive mode with specific server
nslookup - 8 .8.8.8
``
``Copy
Interactive Mode Commands
# Change DNS server
server 8 .8.8.8
``
``Copy
# Set query type to MX
set type = MX
``
``Copy
# Set query type to NS
set type = NS
``
``Copy
# Enable debug mode
set debug
``
``Copy
# Disable debug mode
set nodebug
``
``Copy
# Show all current settings
set all
``
``Copy
# Exit interactive mode
exit
``
``Copy
Advanced Options
Debug and Troubleshooting
# Enable debug output
nslookup -debug google.com
``
``Copy
# Specify custom port
nslookup -port= 53 google.com
``
``Copy
# Set timeout (seconds)
nslookup -timeout= 10 google.com
``
``Copy
# Set retry attempts
nslookup -retry= 3 google.com
``
``Copy
# Use recursive query
nslookup -recurse google.com
``
``Copy
# Disable recursive query
nslookup -norecurse google.com
``
``Copy
# Use TCP instead of UDP
nslookup -vc google.com
``
``Copy
Popular DNS Servers
# Google DNS
nslookup google.com 8 .8.8.8
``
``Copy
# Cloudflare DNS
nslookup google.com 1 .1.1.1
``
``Copy
# OpenDNS
nslookup google.com 208 .67.222.222
``
``Copy
# Quad9 DNS
nslookup google.com 9 .9.9.9
``
``Copy
Common Use Cases
Email Server Troubleshooting
# Check MX records for email routing
nslookup -type= MX example.com
``
``Copy
# Verify mail server IP
nslookup mail.example.com
``
``Copy
Domain Verification
# Check domain ownership via TXT records
nslookup -type= TXT example.com
``
``Copy
# Verify SPF records
nslookup -type= TXT example.com| grep "v=spf1"
``
``Copy
Network Diagnostics
# Check authoritative name servers
nslookup -type= NS example.com
``
``Copy
# Verify reverse DNS
nslookup 192 .168.1.1
``
``Copy
# Check domain authority info
nslookup -type= SOA example.com
``
``Copy
Batch Operations
Multiple Queries
# Query multiple domains from file
nslookup -type= A `` < domains.txt
``Copy
# Pipe domain to nslookup
echo "google.com" | nslookup
``
``Copy
Error Messages
Error
Meaning
** server can't find domain: NXDOMAIN
Domain doesn't exist
** server can't find domain: SERVFAIL
DNS server failure
** server can't find domain: REFUSED
Query refused by server
** Request timed out
No response from DNS server
** No response from server
DNS server unreachable
Installation
Linux (Ubuntu/Debian)
sudo apt-get install dnsutils
Linux (CentOS/RHEL/Fedora)
sudo yum install bind-utils
# or
sudo dnf install bind-utils
Windows
nslookup comes pre-installed with Windows.
macOS
nslookup comes pre-installed with macOS.
Tips and Best Practices
Use specific DNS servers for testing to avoid cached results
Enable debug mode when troubleshooting complex issues
Check multiple record types for comprehensive domain analysis
Use reverse lookups to verify IP address ownership
Compare results from different DNS servers to identify inconsistencies
Interactive mode is useful for multiple queries on the same server
Combine with other tools like dig and host for complete DNS analysis
dig - More detailed DNS lookup tool
host - Simple DNS lookup utility
ping - Test network connectivity
traceroute - Trace network path
whois - Domain registration information