Querying a domain name from the Terminal
A beginner-friendly guide for non-technicians: understand domain, DNS and IP, then ask the right questions with whois, dig and host.
A domain name is the human-readable address of a website — for example example.com — the one you type in a browser. The Terminal lets you ask it simple questions (who manages it, which machine it points to, where mail goes…) without opening your provider’s admin panel.
This guide starts from scratch: every term is explained before it is used. Everywhere below, replace example.com with the domain you care about.
Useful vocabulary (before any command)
Domain name
This is the public name of a website or mailbox: example.com, mydomain.fr. People remember names; machines prefer numbers.
IP address
An IP address is the technical number of a machine on the Internet — a bit like a street number. You will mostly see two forms:
- IPv4: four groups of digits, such as
93.184.216.34 - IPv6: a longer address with letters and colons
When your browser opens example.com, it first needs the IP of the server that hosts the site.
DNS: the Internet phone book
DNS (Domain Name System) is the Internet’s directory system. You give it a domain name; it returns the matching information (often an IP, sometimes something else).
Without DNS, we would have to memorise numbers. With DNS, we keep readable names.
DNS record
One line in that directory is called a DNS record. Each line has at least:
- a type (what it describes: website, mail, alias…)
- a value (the IP, the mail server, some text…)
Changing DNS means editing those lines where your domain’s directory is managed.
Registrar and host (two different roles)
- The registrar is where you buy and renew the domain name (OVH, Gandi, Cloudflare, and so on).
- The host (hosting provider) is where the website actually runs (sometimes the same company, often another).
The registrar holds the name; the host usually holds the content. They meet through DNS: the name points at the host’s machine.
Opening the Terminal
The Terminal is a window where you type commands (short phrases) instead of clicking. It is not reserved for experts: pasting a line and pressing Enter is enough for this guide.
- macOS: Spotlight (
⌘ Space), typeTerminal, Enter. Or Applications → Utilities → Terminal. - Linux: search for “Terminal” in your applications menu, or use your distribution’s usual keyboard shortcut.
You will see a line waiting for input. Paste a command, then Enter. The result appears below.
Installing the tools (if needed)
We will mostly use two programs:
whois— to read the domain’s “ID card”dig— to ask a precise question of the DNS directory
On many Linux systems they are already there. On macOS, dig and whois are often present too. If a command answers “command not found”, install them.
macOS (with Homebrew):
brew install whois bind
(bind provides dig, among other tools.)
Linux (Debian / Ubuntu):
sudo apt install whois dnsutils
Once installed, you can forget about setup.
whois: who is behind this name?
Think of an ID card for the domain: who registered it, with which registrar, until when, and which servers manage its directory.
whois example.com
The output is long. Focus on:
- Registrar — the registration company
- Expiry / Expiration — the end date (an unrenewed domain eventually stops working)
- Name Server — the name servers (the machines that serve this domain’s DNS directory)
Many cards show REDACTED or masked contact data. That is normal. Under privacy rules such as the GDPR, the owner’s personal details are often hidden from the public. It is not a bug: the card remains useful for registrar, dates and name servers.
dig: asking the directory a precise question
dig (domain information groper) queries DNS. Think of it as a clear question to the phone book: “For this name, what is the info of type X?”
Start simple: the site’s IP
dig +short example.com
+short asks for a short answer. You usually get one (or more) IPv4 addresses — that is the A record: “where is the site in IPv4?”
Useful output looks like:
93.184.216.34
You can ignore the rest of the usual dig noise (without +short) at the beginning.
Without +short, dig example.com prints many technical lines. Keep +short while you are learning.
The most useful record types
You specify the type after the domain name.
A — the site’s IPv4 address:
dig +short A example.com
AAAA — the site’s IPv6 address (same idea, different IP format):
dig +short AAAA example.com
MX — servers that receive mail for this domain (Mail eXchange):
dig +short MX example.com
Output looks like 10 mail.example.com. — the number is a priority (lower is preferred); the name after it is the mail server.
NS — name servers: who manages this domain’s DNS directory:
dig +short NS example.com
If those NS no longer match what you expect (an unfinished provider migration, for example), everything else can look “broken” even if the site still lives somewhere else.
TXT — text notes published in DNS. Often used to prove you control the domain, or for email authentication (SPF, DKIM, DMARC):
dig +short TXT example.com
CNAME — an alias: “this name is just another name for…”. Common for www:
dig +short CNAME www.example.com
An empty answer is not always an error: the name may point straight to A/AAAA with no alias.
A short detour: what is www for?
A subdomain is a prefix in front of the main name. In www.example.com, the subdomain is www; the “root” domain remains example.com.
www stands for World Wide Web. It is the historic name of the web service, conceived by Tim Berners-Lee (often nicknamed TimBL), pioneer of the Web at CERN in the early 1990s. Back then, services on the same machine were clearly separated: www for pages, mail for email, ftp for files, and so on. The browser looked up www.example.com the way you would look for the domain’s “web door”.
Today many sites also (or only) answer on example.com without www. Technically, both can point at the same site. In my practice, I systematically add www on my sites and my clients’ — and I make sure both variants work (often one redirects to the other) — as a nod to TimBL and to keep that readable landmark of the Web of its origins. On 6 August 2026 we also marked 35 years of the Web open to the public: TimBL’s 6 August 1991 invitation to try the WorldWideWeb.
To check both:
dig +short A example.com
dig +short A www.example.com
If one of them does not answer while the site “works” in the browser on the other address, it is often a missing DNS record or redirect.
From IP back to a name
Sometimes you have an IP and want to know which name is associated with it (when that is published):
dig +short -x 93.184.216.34
That is the reverse direction: from IP to a name. It is not always filled in.
Asking another “directory”
By default, dig uses your network’s DNS resolver (your home router, your company, and so on). To compare with a well-known public directory:
dig +short example.com @8.8.8.8
Here @8.8.8.8 means: “ask that DNS server” (Google’s, widely used for this kind of check). If your router and @8.8.8.8 disagree right after a change, the change is often not visible everywhere yet — you may need to wait a little.
host: the lighter version
host asks the same kind of questions, often with output that is easier for a beginner to read:
host example.com
Example reply:
example.com has address 93.184.216.34
For mail:
host -t MX example.com
Keep dig +short when you want a minimal answer; use host when you want a readable sentence.
What about nslookup?
nslookup still exists on many machines and also queries DNS. To get started, dig and host are enough — and usually clearer. You can skip it without missing the essentials.
Guided scenario: “my site no longer loads”
Ask the questions in this order. One anomaly is often enough to explain the problem.
1. Who manages the directory? (NS)
dig +short NS example.com
- Good sign: name server names you recognise (your registrar or DNS host).
- Bad sign: an empty list, or servers from an old provider when you thought you had migrated.
2. Where does the site point? (A / AAAA)
dig +short A example.com
dig +short AAAA example.com
- Good sign: an IP that matches your current hosting.
- Bad sign: no answer, or an IP from an old server / another project.
Compare with another directory if needed:
dig +short A example.com @8.8.8.8
3. And mail? (MX), if the issue is “email no longer sends / arrives”
dig +short MX example.com
- Good sign: the MX servers you expect (Google, Microsoft, your mail host…).
- Bad sign: no MX, or a forgotten server after a change.
For TXT records related to spam and mailbox trust, continue with the SPF, DKIM and DMARC guide.
Going further
- The Linux commands cheat sheet lists more networking one-liners once these basics click.
- Email authentication shows how to read the TXT records that protect your domain from spoofing.
In short: DNS is a directory, whois reads the name’s ID card, dig and host ask that directory precise questions. With three commands and the vocabulary above, you can already diagnose the essentials — before opening any admin panel.
Go further
Browsing the notes 33 published