People remember names; networks route numbers. The Domain Name System is the global, distributed database that turns blog.jefersonjeronimoai.online into an IP address, tells mail servers where to deliver your email and proves you own a domain to certificate authorities. It answers billions of queries a second, and when it breaks, everything looks broken. Hence the saying: “It’s always DNS.”
The hierarchy
DNS names are read right to left, from the most general to the most specific:
blog . jefersonjeronimoai . online . (root)
host second-level domain TLD
| Level | Who runs it | Example |
|---|---|---|
| Root | 13 named root server identities (hundreds of anycast instances) | . |
| TLD (top-level domain) | Registry operators | .com, .org, .online, .br |
| Second-level domain | You, through a registrar | jefersonjeronimoai.online |
| Subdomains | You, in your zone | blog., k8s-game., api. |
Each level delegates the next one with NS records. The root knows who runs .online, .online knows who runs jefersonjeronimoai.online, and that zone holds the actual records.
Who answers
- Stub resolver: the small client in your OS. It asks one question and expects a final answer.
- Recursive resolver: does the legwork for you and caches results. Usually your ISP’s, your router’s, or a public one such as
1.1.1.1,8.8.8.8or9.9.9.9. - Authoritative server: holds the zone and gives the official answer for it. It never chases other servers for you.
A lookup step by step
You type blog.example.com with an empty cache:
- The stub asks the recursive resolver: “A record for blog.example.com?”
- The resolver asks a root server, which replies: “I don’t know, but
.comis served by these servers” (a referral). - The resolver asks a .com server, which refers it to
example.com‘s name servers. - The resolver asks the authoritative server for
example.com, which answers:blog.example.com A 203.0.113.25. - The resolver caches every answer for its TTL and returns the final result to the stub.
Step 1 is a recursive query (“give me the answer”); steps 2 to 4 are iterative queries (“tell me what you know”). dig +trace performs the iteration itself and shows every step:
$ dig +trace blog.example.com | grep -E 'IN\s+(NS|A)\s' | head -6
. 518400 IN NS a.root-servers.net.
com. 172800 IN NS a.gtld-servers.net.
example.com. 172800 IN NS ns1.example-dns.net.
example.com. 172800 IN NS ns2.example-dns.net.
blog.example.com. 300 IN A 203.0.113.25
Record types
| Type | Holds | Example |
|---|---|---|
| A | IPv4 address | blog A 203.0.113.25 |
| AAAA | IPv6 address | blog AAAA 2001:db8::25 |
| CNAME | Alias to another name | www CNAME blog.example.com. |
| MX | Mail server and priority (lower first) | @ MX 10 mail.example.com. |
| TXT | Free text: SPF, DKIM, DMARC, domain verification | @ TXT "v=spf1 mx -all" |
| NS | Name servers for a zone | @ NS ns1.example-dns.net. |
| SOA | Zone metadata: primary server, serial, timers | one per zone |
| PTR | Reverse lookup: IP to name | 25.113.0.203.in-addr.arpa PTR blog.example.com. |
| SRV | Service host and port | _sip._tcp SRV 10 60 5060 sip.example.com. |
| CAA | Which CAs may issue certificates | @ CAA 0 issue "letsencrypt.org" |
| HTTPS / SVCB | Connection hints: HTTP/3 support, alternative endpoints | @ HTTPS 1 . alpn="h3,h2" |
Two rules trip people up: a CNAME cannot coexist with other records on the same name (so the bare domain example.com cannot be a CNAME; providers offer “ALIAS” or “flattening” instead), and MX and NS records must point to names, never to IP addresses.
Querying DNS
$ dig blog.example.com
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40112
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; ANSWER SECTION:
blog.example.com. 287 IN A 203.0.113.25
;; Query time: 14 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
Things to read: status (NOERROR, NXDOMAIN for “name does not exist”, SERVFAIL for “the resolver could not get an answer”), the flags (aa means an authoritative answer, ra recursion available), the TTL (287 seconds left in the cache) and which server answered.
Handy variations:
$ dig +short example.com MX
10 mail.example.com.
$ dig @1.1.1.1 +short blog.example.com
203.0.113.25
$ dig @ns1.example-dns.net blog.example.com +norecurse
$ dig -x 203.0.113.25 +short
blog.example.com.
$ resolvectl query blog.example.com
blog.example.com: 203.0.113.25 -- link: enp3s0
@server asks a specific resolver, which is how you compare what different resolvers see. Asking the authoritative server directly with +norecurse shows the truth without any cache. On Windows, use Resolve-DnsName blog.example.com -Type A or nslookup.
TTL and caching
Every record has a TTL (time to live) in seconds. Resolvers cache answers for that long, which makes DNS fast but means changes are not instant. Before a migration:
- Lower the TTL (for example from 3600 to 60) at least one old TTL ahead of the change.
- Change the record.
- Raise the TTL again once everything works.
“DNS propagation” is really just caches expiring. Failed lookups are cached too (negative caching, governed by the SOA’s minimum field), so querying a name before you create it can make it look missing for a while.
Where your machine gets its answers
On Linux the order is set in /etc/nsswitch.conf (hosts: files dns means /etc/hosts first). Many distributions run systemd-resolved as a local cache at 127.0.0.53:
$ resolvectl status enp3s0 | grep -E 'DNS Servers|DNS Domain'
DNS Servers: 192.168.1.1
DNS Domain: lan
$ grep -v '^#' /etc/hosts
127.0.0.1 localhost
192.168.1.50 nas.lan
$ sudo resolvectl flush-caches
On Windows: Get-DnsClientServerAddress shows the servers and ipconfig /flushdns clears the cache.
DNS security
- DNSSEC signs records so resolvers can verify they were not forged in transit (it does not encrypt them). The
adflag in adiganswer means the resolver validated the signatures. - Encrypted DNS hides queries from the network: DoT (DNS over TLS, TCP 853), DoH (DNS over HTTPS, 443) and DoQ (DNS over QUIC). Browsers and phones increasingly use DoH by default.
- Cache poisoning tries to inject fake answers into a resolver; random source ports, random query IDs and DNSSEC defend against it.
- Open resolvers that answer anyone get abused for amplification attacks; only serve your own clients.
- Split-horizon DNS gives internal clients different answers (private IPs) from external ones.
Classic DNS failures
| Symptom | Likely cause | Check |
|---|---|---|
ping 1.1.1.1 works, ping example.com fails | No working resolver | resolvectl status, dig @1.1.1.1 example.com |
NXDOMAIN | Typo, missing record, wrong zone, or a delegation not set at the registrar | dig +trace |
SERVFAIL | Authoritative servers unreachable, or DNSSEC validation failed | dig +cd (skips validation) to compare |
| Old IP still returned | Cached record with a long TTL | Query the authoritative server directly |
| Works on one machine, not another | Different resolvers, /etc/hosts overrides, VPN DNS | Compare dig @server results |
| Mail bounces | Missing or wrong MX, SPF, DKIM or DMARC | dig MX, dig TXT |
Exercise
dig returns status: NXDOMAIN for api.example.com. What does that mean?
Show answer
Answer: B. NXDOMAIN is a definitive “no such name”. A resolver problem or a failed DNSSEC validation shows up as SERVFAIL instead.
Exercise
You will move a website to a new IP tomorrow. Its A record has a TTL of 86,400 seconds. What should you do today?
Show answer
Answer: D. Resolvers may keep the old answer for up to the old TTL. Lowering it a full old TTL ahead means caches refresh quickly when you switch.
Exercise
Which record tells other mail servers where to deliver email for your domain?
Show answer
Answer: C. MX records list mail servers with priorities. TXT holds SPF, DKIM and DMARC policies that help receivers trust your mail, but delivery targets come from MX.
Key takeaways
- DNS is a hierarchy: root, TLD, your zone, delegated with NS records.
- Recursive resolvers chase and cache answers; authoritative servers hold the truth.
- Know A, AAAA, CNAME, MX, TXT, NS, PTR and CAA by heart.
- TTLs control caching; lower them before migrations.
dig,dig +traceanddig @serversolve most DNS mysteries.
FAQ
What is the difference between NXDOMAIN and SERVFAIL?
NXDOMAIN is a valid answer: the name does not exist. SERVFAIL means the resolver could not get any trustworthy answer, often because the authoritative servers are unreachable or DNSSEC signatures do not validate.
Does DNS use TCP or UDP?
Usually UDP port 53. It switches to TCP for large answers, zone transfers and when a UDP reply is truncated. Encrypted variants use TCP 853 (DoT), HTTPS 443 (DoH) or QUIC (DoQ).
Why does my change show up for some people and not others?
Their resolvers still hold the old record in cache until its TTL runs out. Querying the authoritative server shows whether your change is live.
What is reverse DNS used for?
PTR records map IPs to names. Mail servers check them to judge senders, and logs and traceroute use them to show names. The owner of the IP block (usually your ISP or cloud provider) controls them.