Skip to main content

terminal Complete Reference Guide

DNS Commands Cheat Sheet

Master every DNS command for Windows, macOS, and Linux. Copy-paste examples for nslookup, dig, host, flush DNS, and more.

nslookup Command

nslookup (Name Server Lookup) is the most widely used DNS command, available on Windows, macOS, and Linux. It queries DNS servers to retrieve domain name records.

play_arrow Basic A Record Lookup

Query the default DNS server for a domain's A record (IPv4 address).

nslookup example.com

play_arrow Query Specific Record Types

Use -type= to look up specific DNS record types like MX, TXT, CNAME, NS, or AAAA.

# Look up MX records (mail servers) nslookup -type=MX example.com # Look up TXT records (SPF, DKIM, DMARC) nslookup -type=TXT example.com # Look up CNAME records (aliases) nslookup -type=CNAME www.example.com # Look up NS records (nameservers) nslookup -type=NS example.com # Look up AAAA records (IPv6) nslookup -type=AAAA example.com

play_arrow Query a Specific DNS Server

Add a DNS server address after the domain to query that server directly. Useful for checking if a specific resolver has updated records.

# Query Google's public DNS nslookup example.com 8.8.8.8 # Query Cloudflare's DNS nslookup example.com 1.1.1.1 # Combine record type and server nslookup -type=MX example.com 8.8.8.8

dig Command

dig (Domain Information Groper) is the most powerful DNS query tool, preferred by system administrators. Available on macOS and Linux by default. On Windows, install via BIND or use WSL.

play_arrow Basic DNS Query

Run a full DNS query that shows the QUESTION, ANSWER, AUTHORITY, and ADDITIONAL sections.

dig example.com

play_arrow Query Specific Record Types

Specify the record type after the domain name.

# Look up MX records dig example.com MX # Look up TXT records dig example.com TXT # Look up ALL record types dig example.com ANY # Look up NS records dig example.com NS

play_arrow +short Flag (Concise Output)

The +short flag strips all extra information and returns only the answer.

# Get just the IP address dig example.com +short 93.184.216.34 # Get just the MX servers dig example.com MX +short 10 mail.example.com.

play_arrow +trace (Full Resolution Path)

Trace the entire DNS resolution chain from root servers to the authoritative nameserver. Essential for diagnosing propagation and delegation issues.

# Trace the full DNS resolution path dig example.com +trace # Trace with short answers at each step dig example.com +trace +short

play_arrow Query a Specific DNS Server

Use the @server syntax to direct your query to a specific resolver.

# Query Google DNS dig @8.8.8.8 example.com # Query Cloudflare DNS dig @1.1.1.1 example.com +short # Query a domain's authoritative nameserver directly dig @ns1.example.com example.com A

host Command

host is a simple DNS lookup utility available on macOS and Linux. It provides cleaner, more readable output than dig, making it great for quick lookups.

play_arrow Basic Usage

Returns A, AAAA, and MX records by default in a human-readable format.

# Basic lookup (shows A, AAAA, MX) host example.com example.com has address 93.184.216.34 example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946 example.com mail is handled by 0 . # Look up specific record type host -t MX example.com host -t TXT example.com host -t NS example.com # Verbose output (similar to dig) host -v example.com # Query a specific DNS server host example.com 8.8.8.8

Windows CMD DNS Commands

Windows Command Prompt includes built-in tools for DNS lookups and cache management. Open CMD by pressing Win + R, typing cmd, and pressing Enter.

play_arrow nslookup in CMD

The nslookup command works identically in Windows CMD as described above.

:: Basic DNS lookup nslookup example.com :: Look up MX records nslookup -type=MX example.com :: Query Google DNS specifically nslookup example.com 8.8.8.8

play_arrow View & Flush DNS Cache

Windows caches DNS lookups locally. Use these commands to view or clear the cache.

:: Display the local DNS cache ipconfig /displaydns :: Flush (clear) the DNS cache (requires Admin) ipconfig /flushdns Successfully flushed the DNS Resolver Cache. :: View current DNS server configuration ipconfig /all | findstr "DNS Servers"

PowerShell DNS Commands

Windows PowerShell provides the Resolve-DnsName cmdlet, which is more powerful and scriptable than nslookup.

play_arrow Resolve-DnsName

A modern, object-oriented DNS query tool built into PowerShell 5.1+ and PowerShell 7+.

# Basic A record lookup Resolve-DnsName example.com # Look up specific record type Resolve-DnsName example.com -Type MX Resolve-DnsName example.com -Type TXT Resolve-DnsName example.com -Type NS Resolve-DnsName example.com -Type AAAA # Query a specific DNS server Resolve-DnsName example.com -Server 8.8.8.8 # Get just the IP addresses (Resolve-DnsName example.com).IPAddress # Flush DNS cache in PowerShell Clear-DnsClientCache

Flush DNS Cache (All Operating Systems)

Flushing your DNS cache forces your computer to query DNS servers for fresh records. This is essential after changing DNS settings or when websites aren't loading correctly due to stale cached entries.

play_arrow Windows (CMD or PowerShell as Admin)

:: Command Prompt (run as Administrator) ipconfig /flushdns :: PowerShell (run as Administrator) Clear-DnsClientCache :: Verify cache is empty ipconfig /displaydns

play_arrow macOS (Terminal)

# macOS Ventura, Sonoma, Sequoia (14+) sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder # macOS Monterey & Big Sur sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder # macOS Catalina & Mojave sudo killall -HUP mDNSResponder

play_arrow Linux (Terminal)

# systemd-resolved (Ubuntu 18.04+, Fedora, Arch) sudo systemd-resolve --flush-caches # Or the newer command sudo resolvectl flush-caches # Verify the cache was flushed sudo systemd-resolve --statistics # nscd (if using Name Service Cache Daemon) sudo systemctl restart nscd # dnsmasq (if using dnsmasq) sudo systemctl restart dnsmasq

play_arrow Google Chrome Browser

Chrome has its own internal DNS cache separate from the operating system.

# Open this URL in Chrome's address bar: chrome://net-internals/#dns # Then click "Clear host cache" # Also flush socket pools: chrome://net-internals/#sockets # Click "Flush socket pools"

Skip the Terminal. Use DNS Dingo.

Why memorize commands when you can check DNS records, monitor propagation, and track changes from a single dashboard? DNS Dingo gives you the same data with a better experience.

Frequently Asked Questions

What is the nslookup command?

nslookup (Name Server Lookup) is a command-line tool available on Windows, macOS, and Linux that queries DNS servers to find DNS records for a domain. You can use it to look up A, AAAA, MX, CNAME, TXT, NS, and other record types. Basic syntax: nslookup example.com

What is the difference between nslookup and dig?

Both nslookup and dig query DNS servers, but dig provides more detailed output including the query time, server used, and full DNS response sections (QUESTION, ANSWER, AUTHORITY, ADDITIONAL). dig is preferred by system administrators for troubleshooting because of its verbose output and support for advanced options like +trace and +short.

How do I flush DNS cache on Windows?

Open Command Prompt as Administrator and run ipconfig /flushdns. You should see "Successfully flushed the DNS Resolver Cache." You can verify the cache is empty by running ipconfig /displaydns.

How do I flush DNS cache on macOS?

Open Terminal and run sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder. This works on macOS Ventura, Sonoma, and later. You will be prompted for your admin password.

How do I check DNS records without the command line?

Use online DNS lookup tools like DNS Dingo to check DNS records without any command-line knowledge. Enter the domain name and the tool will query DNS servers and display all record types in a user-friendly interface.

What does the dig +trace command do?

The dig +trace command traces the full DNS resolution path from root DNS servers to the authoritative nameserver. It shows each delegation step, making it invaluable for diagnosing DNS propagation issues, delegation problems, and identifying where DNS resolution breaks.