DNS — Names to Addresses
You move notes-api to a new server and update the DNS record. Your laptop sees the new server; a colleague's still hits the old one for an hour. Nothing is broken: that is DNS caching doing exactly what it was told.
The rule
DNS turns names into records, and every answer is cached for its TTL.
The Domain Name System is a distributed database of records attached to names. The ones you will use most:
| Record | Maps a name to | Example |
|---|---|---|
A |
an IPv4 address | notes.example.com → 203.0.113.10 |
AAAA |
an IPv6 address | notes.example.com → 2001:db8::10 |
CNAME |
another name (an alias) | www.example.com → example.com |
MX |
the mail servers for a domain | example.com → mail.example.com |
TXT |
free text, often for verification and email policy | |
NS |
the name servers responsible for a domain |
How a lookup works: your machine asks a recursive resolver (from your ISP, company, or a public one). If the resolver has no cached answer, it asks a root server, which points to the .com servers, which point to the domain's authoritative name servers, which give the real answer. The resolver then caches it for the record's TTL (time to live, in seconds).
dig notes.example.com +short # just the answer
dig notes.example.com # full answer, including the TTL
dig @1.1.1.1 notes.example.com # ask a specific resolver
dig example.com MX +short # a specific record typeThe shortcut
Before any DNS change, lower the TTL first and wait for the old TTL to pass. A 3600-second TTL means resolvers may keep the old answer for an hour after you change it. Drop it to 60 a day ahead, make the change, then raise it again.
Read the current record
dig notes.example.comshows anArecord for203.0.113.10with TTL 3600.
When DNS "has not updated", ask which resolver you are querying and what TTL it was given. dig @<resolver> against a few resolvers usually explains the mystery.
Drills
Answer fast — trust the rule.
Which record type maps a name to an IPv6 address?
You want www.example.com to be an alias for example.com. Which record?
A record has a TTL of 3600. What does that allow resolvers to do?
Which server holds the real, original records for example.com?
Remember
- DNS turns names into records, and every answer is cached for its TTL.
- Shortcut: lower the TTL well before a change, then switch, then raise it.
- Trap: "DNS is broken" when a resolver is just serving a cached answer.
