コンテンツにスキップ

Nslookup - DNS Lookup and Troubleshooting

`` ``
✅ All commands copied to clipboard!

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
``
# Look up using specific DNS server
nslookup google.com 8.8.8.8
``
# Reverse DNS lookup (IP to domain)
nslookup 8.8.8.8
``

Record Type Queries

# A record (IPv4 address)
nslookup -type=A google.com
``
# AAAA record (IPv6 address)
nslookup -type=AAAA google.com
``
# MX record (Mail Exchange)
nslookup -type=MX google.com
``
# NS record (Name Server)
nslookup -type=NS google.com
``
# TXT record (Text records)
nslookup -type=TXT google.com
``
# CNAME record (Canonical Name)
nslookup -type=CNAME www.google.com
``
# SOA record (Start of Authority)
nslookup -type=SOA google.com
``
# PTR record (Pointer for reverse lookup)
nslookup -type=PTR 8.8.8.8
``
# ANY record (All available records)
nslookup -type=ANY google.com
``
# SRV record (Service record)
nslookup -type=SRV _sip._tcp.example.com
``

Interactive Mode

Starting Interactive Mode

# Enter interactive mode
nslookup
``
# Enter interactive mode with specific server
nslookup - 8.8.8.8
``

Interactive Mode Commands

# Change DNS server
server 8.8.8.8
``
# Set query type to MX
set type=MX
``
# Set query type to NS
set type=NS
``
# Enable debug mode
set debug
``
# Disable debug mode
set nodebug
``
# Show all current settings
set all
``
# Exit interactive mode
exit
``

Advanced Options

Debug and Troubleshooting

# Enable debug output
nslookup -debug google.com
``
# Specify custom port
nslookup -port=53 google.com
``
# Set timeout (seconds)
nslookup -timeout=10 google.com
``
# Set retry attempts
nslookup -retry=3 google.com
``
# Use recursive query
nslookup -recurse google.com
``
# Disable recursive query
nslookup -norecurse google.com
``
# Use TCP instead of UDP
nslookup -vc google.com
``
# Google DNS
nslookup google.com 8.8.8.8
``
# Cloudflare DNS
nslookup google.com 1.1.1.1
``
# OpenDNS
nslookup google.com 208.67.222.222
``
# Quad9 DNS
nslookup google.com 9.9.9.9
``

Common Use Cases

Email Server Troubleshooting

# Check MX records for email routing
nslookup -type=MX example.com
``
# Verify mail server IP
nslookup mail.example.com
``

Domain Verification

# Check domain ownership via TXT records
nslookup -type=TXT example.com
``
# Verify SPF records
nslookup -type=TXT example.com|grep "v=spf1"
``

Network Diagnostics

# Check authoritative name servers
nslookup -type=NS example.com
``
# Verify reverse DNS
nslookup 192.168.1.1
``
# Check domain authority info
nslookup -type=SOA example.com
``

Batch Operations

Multiple Queries

# Query multiple domains from file
nslookup -type=A ``< domains.txt
# Pipe domain to nslookup
echo "google.com"|nslookup
``

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

  1. Use specific DNS servers for testing to avoid cached results
  2. Enable debug mode when troubleshooting complex issues
  3. Check multiple record types for comprehensive domain analysis
  4. Use reverse lookups to verify IP address ownership
  5. Compare results from different DNS servers to identify inconsistencies
  6. Interactive mode is useful for multiple queries on the same server
  7. 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