Skip to main content

Understanding nslookup

The nslookup (Name Server Lookup) command is one of the most essential tools for network diagnostics. It allows you to query DNS servers to find the IP address of a domain or verify other DNS records like MX, TXT, or CNAME.

info

Think of nslookup as a phone book for the Internet — it helps you find the phone number (IP address) associated with a person’s name (domain).

What Is nslookup?

nslookup stands for Name Server Lookup. It’s a command-line tool available on Windows, macOS, and Linux that helps you:

  • Check if a domain name resolves correctly to an IP address.
  • View DNS records for troubleshooting.
  • Identify name server (NS) or mail server (MX) configurations.
  • Diagnose DNS-related issues such as incorrect resolution or timeouts.

Basic Syntax

nslookup [options] [domain] [dns-server]
ParameterDescription
domainThe domain name you want to query (e.g., codeharborhub.github.io)
dns-server(Optional) The specific DNS server you want to use
optionsFlags or arguments to modify the behavior

Example:

nslookup codeharborhub.github.io

Output:

Server:  dns.google
Address: 8.8.8.8

Non-authoritative answer:
Name: codeharborhub.github.io
Address: 185.199.108.153

How nslookup Works

When you run nslookup, it sends a query to a DNS resolver. The resolver checks its cache or contacts authoritative name servers to find the answer.

Common Use Cases

PurposeCommandDescription
Basic IP lookupnslookup google.comReturns the IP address for the domain
Use a specific DNS servernslookup codeharborhub.github.io 8.8.8.8Queries Google DNS (8.8.8.8)
Check MX recordsnslookup -type=mx gmail.comLists mail servers for Gmail
View Name Serversnslookup -type=ns github.comShows authoritative DNS servers
View TXT recordsnslookup -type=txt openai.comDisplays domain verification or SPF records
Reverse lookupnslookup 8.8.8.8Finds the domain name associated with an IP

Interactive Example

Live Editor
function NslookupDemo() {
  const [domain, setDomain] = React.useState("codeharborhub.github.io");
  const [response, setResponse] = React.useState("");

  const handleLookup = () => {
    setResponse(`Non-authoritative answer:
Name: ${domain}
Address: 185.199.108.153`);
  };

  return (
    <div style={{ textAlign: "center" }}>
      <h3>Simulate nslookup Command</h3>
      <input
        type="text"
        value={domain}
        onChange={(e) => setDomain(e.target.value)}
        style={{ padding: "8px", width: "60%", borderRadius: "8px" }}
      />
      <br />
      <button
        style={{
          marginTop: "10px",
          padding: "8px 16px",
          borderRadius: "6px",
          cursor: "pointer",
        }}
        onClick={handleLookup}
      >
        Run Lookup
      </button>
      <pre style={{ marginTop: "15px", textAlign: "left" }}>{response}</pre>
    </div>
  );
}
Result
Loading...

In this simulation, you can enter any domain name and click "Run Lookup" to see a mock response similar to what nslookup would return.

Types of DNS Records You Can Query

Record TypeDescriptionExample
AMaps a domain name to an IPv4 address185.199.108.153
AAAAMaps a domain to an IPv6 address2606:50c0:8001::153
MXIdentifies mail servers for the domainaspmx.l.google.com
NSLists authoritative name serversns1.github.io
CNAMEProvides alias nameswww → codeharborhub.github.io
TXTStores verification or SPF info"v=spf1 include:_spf.google.com"

Common Issues and Errors

ErrorMeaning
*** Can't find server nameDNS resolver not configured properly
Non-existent domainThe queried domain does not exist
Request timed outDNS server not responding
NXDOMAINThe domain name can’t be resolved

Example: Query Timing

If a DNS query takes 50 ms to respond and you perform 4 lookups:

Average Query Time=50+48+52+504=50 msAverage\ Query\ Time = \frac{50 + 48 + 52 + 50}{4} = 50\text{ ms}

That means your DNS response time averages around 50 milliseconds, which is quite fast.

note

Keep in mind that DNS caching can affect response times. Subsequent queries for the same domain may return faster results due to cached data.

Quick Commands Reference

# Basic domain lookup
nslookup codeharborhub.github.io

# Query using Cloudflare DNS
nslookup codeharborhub.github.io 1.1.1.1

# Check mail records
nslookup -type=mx example.com

# Find authoritative name servers
nslookup -type=ns example.com

Key Takeaways

  • nslookup queries DNS servers to fetch IPs and record details.
  • It’s useful for troubleshooting, validation, and network diagnostics.
  • Works across platforms (Windows, macOS, Linux).
  • Helps identify DNS misconfigurations, delays, or missing records.
  • Understanding DNS records (A, MX, NS, CNAME, TXT) is crucial for effective use of nslookup.