• About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings
Monday, November 2, 2026
  • Login
PacketNebula
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download
No Result
View All Result
PacketNebula
No Result
View All Result
Home Network

How to do a DNS lookup from the command line

by Stéphane Cardon
3 September 2026
in Network
0
Blue, grey, green, red and yellow Ethernet patch cables plugged into the ports of a rack-mounted network switch

Image: Raysonho @ Open Grid Scheduler / Grid Engine / Wikimedia Commons, CC0

Share on FacebookShare on Twitter

You push a DNS change, then sit there wondering if it actually took. Don't wonder, ask: nslookup example.com works on any OS, Windows included, and confirms a name resolves or that a fresh record went live. When we want detail we reach for dig. dig +short example.com prints just the answer, and dig MX example.com or dig TXT example.com pull one record type so you're not wading through the rest. The bit worth memorising is the @ syntax. dig @8.8.8.8 example.com asks a specific resolver and steps around your own cache, which is how we check whether a change has actually propagated. Below: the commands, plus what the output is really telling you.

The short answer

nslookup example.com works everywhere. On Linux and macOS we run dig example.com for the full picture and dig +short example.com for just the answer. Add a type (dig MX example.com) or a resolver (dig @1.1.1.1 example.com).

nslookupany OS, including Windows
dig +shortjust the answer, Linux and macOS
@8.8.8.8query a specific resolver
Answer card showing nslookup on any OS, dig and dig +short on Linux and macOS, plus querying a specific resolver with @.
nslookup everywhere, dig for detail, @resolver to bypass your cache.

nslookup for portability, dig for detail

nslookup is on every box we touch, Windows included, and that’s the whole reason we keep it in hand. Give it a name and it prints the addresses, after a couple of lines telling you which server answered. Those first lines are your own resolver, not the result. They trip everyone up once.

Windows
nslookup example.com

On Linux and macOS, dig is the one worth learning. Out of the box it prints a full report with the TTL and the authority section. Gold when you’re debugging. Noise when you’re not. +short cuts it down to just the answer, one value per line:

Linux
dig +short example.com

Ask for one record type

Mail not arriving? Check MX. Chasing an SPF record or a domain-verification string? That lives in TXT. Name the type and dig fetches only that, which beats reading a whole zone to find one line:

Linux
dig MX example.com
Terminal showing dig +short returning an address, then dig MX listing mail servers with priorities.
dig +short for the address, dig MX for the mail servers behind a domain.

Bypass your cache to check propagation

Point the query at a public resolver with @. If a freshly changed record shows up there but not from your default resolver, you’re just waiting for the old cached copy to expire:

Linux
dig @8.8.8.8 example.com

Prefer clicking to typing? The DNS lookup tool queries every record type in one click, and what DNS TTL means explains the propagation wait.

Three dig habits worth having, because they answer the questions that come straight after "what’s the record".

+short strips everything except the answer, which is what makes dig usable inside scripts. Pointing at a specific resolver with @ is how you tell "my machine is caching" apart from "the change hasn’t published", since you can ask the authoritative server directly and compare. And +trace walks the delegation from the root down, which is the fastest way to find the point where a broken zone stops answering.

Linux and macOS
dig +short A example.com @1.1.1.1
Linux and macOS
dig +trace example.com

One note on nslookup, since it worries people: the "Non-authoritative answer" line it prints is normal. It just means the reply came from a cache rather than from the zone’s own server, which is true of nearly every lookup you’ll ever run.

If you only take one of the two away, make it dig. nslookup is everywhere and it’s fine for a quick answer, but it won’t tell you what you need when a zone is genuinely broken, and that’s exactly when you’re looking.

Frequently asked questions

Should I use nslookup or dig?

nslookup when you just want a quick answer and it's the only tool installed, which on Windows it is. dig when you want detail or you're scripting: it shows the exact records with their TTLs and tells you which server answered, and "dig +short" gives clean output you can pipe. dig isn't installed by default on Windows, so nslookup is the portable choice there.

How do I look up just one record type, like MX or TXT?

Name the type. With dig, "dig MX example.com" pulls the mail servers and "dig TXT example.com" the SPF and verification records. IPv6? "dig AAAA example.com". With nslookup it's "nslookup -type=MX example.com". That's how we debug mail flow or confirm an SPF record without wading through everything else.

What does dig +short do?

It strips the full report down to just the answer values, one per line. "dig +short example.com" prints the IP addresses and nothing else, which is exactly what we want at a glance or in a script. Drop the +short when you miss the TTL and the authority section.

How do I check if a DNS change has propagated?

Query a public resolver directly so you skip your own cache: "dig @8.8.8.8 example.com" asks Google DNS, "dig @1.1.1.1 example.com" asks Cloudflare. New value shows there but not from your default resolver? You're just waiting for the old record cached locally to expire, and that wait is the TTL.

Tags: clidnsguidenetwork
ShareTweet
Previous Post

How to show your IP address from the command line

Next Post

How to secure a new Ubuntu VPS

Stéphane Cardon

Stéphane Cardon

Network cybersecurity engineer: architecture, LAN and WLAN, system administration. He runs PacketNebula, where he publishes the tools and answers he wanted for his own work.

Next Post
Brass padlock with its key still in the lock, closed on a steel chain in front of a tiled wall

How to secure a new Ubuntu VPS

Free tools

  • IPv4 subnet calculator
  • DNS lookup
  • SSL certificate checker
  • HTTP headers checker
  • SPF, DKIM and DMARC checker
  • JWT decoder
  • Cron expression builder
  • Chmod calculator
  • Password generator

All 24 tools →

Guides to keep handy

  • Flush the DNS cache on Windows
  • Kill the process using a port
  • Generate an SSH key
  • Secure a new Ubuntu VPS
  • Find files on Linux
  • Extract and create tar.gz

More guides →

Who writes this

Stéphane Cardon, network cybersecurity engineer. Architecture, LAN and WLAN, system administration. PacketNebula holds the tools and answers he wanted for his own work.

About this site →

  • About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings

Copyright © 2026 Stephane Cardon.

No Result
View All Result
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download

Copyright © 2026 Stephane Cardon.

Cookies, your call

We use Google Analytics to see which pages get read. Once our AdSense application is approved, articles and guides will carry Google ads. Nothing runs until you say yes, and nothing runs on the tool pages. Details