You are on page 1of 28

by Julia Evans

WAN
208.94.117.43

=XAA\Pl=
CA7.COA\
about +his zine
Hello! This zine is about DNS: the A^Domain Name System 4r

My goal is to help you get from:

o
1 updated my site's IP address
and... nothing changed? V/hy????

o o oh, my DNS is doing something v/eird?


o
No problem, I can figure it out v/ith
a little bit of dig .----

Let's go learn hov/ DNS v/orks!


"table of contents
............................................overview_______________________
cast of characters_______ A life of a DNS cjuery........... 7
resolvers vs authoritative...... 5 DNS records................... 8
the DNS hierarchy................ f> DNS packets....................

search domains- 21
TCP DNS............... 22

’ DNS record types |g|

A 2 AAAA........ 23 MX......................... 25
CNAME................. 2H “TXT......................26
cast ot characters H
Let's meet the cast and see how they communicate with each other!

where's example.com? where's example.com?


----- DNS query —►

<---------------------
93.1S4.216.34! 93.184.216.34! 93.184.216.34!
browser resolver authoritative
nameservers
Your browser uses Your operating The function sends The authoritative
DNS to look up IP system provides a requests to a nameservers are the
addresses every function to do DNS server called a servers where the DNS
time it visits a lookups. On Linux resolver which records are actually
domain, like and Mac it's knows how to find stored. They're wearing
example.com. getaddrinfo. the authoritative crowns because they're
nameservers. In Charge.
The browser has Your operating The resolver has
a DNS cache. system also might a DNS cache.
have a DNS cache.
resolvers vs
anytime your browser anytime you update a
One reason DNS is confusing
is that the DNS server you makes a DNS query, it's domain's DNS records,
query (a resolver ) is asking a resolver you're updating an
different from the DNS authoritative nameserver
server where the records set the IP for
are stored (a network of example.com to 1.2.3.4
authoritative nameservers
/got it! Next time 'X
I someone asks, that's LJ ■ • A
\jmhat I'll tell them, y L^J

how a resolver how an the terminology is


handles queries authoritative nameserver really confusing
handles queries
Other names for resolvers:
Q check its cache, or Q check its database for recursive resolver recursive nameserver
(if that fails) DNS recursor DNS resolution service
a match public DNS server caching-only nameserver

©find the right authoritative ©that's it, there's no step 2. Types of authoritative nameservers:
nameserver and ask it It's the authority! root nameserver
TLD nameserver (like .com or .ca)
the DNS hierarchy
there are 3 main levels of authoritative DNS servers the root nameserver
delegates
the IP for example.com?)

l am not concerned with


petty details like that.
Here's the address of
the .com nameserver. root

the .com nameserver the example.com this design lets DNS


also delegates nameserver actually be decentralized
<^what's the IP for example.com?) answers your questions
example: for my domain jvns.ca
what's the IP for
Tarn not concerned
example.com? .
with petty details jvns.ca
root .ca nameserver
like that either. nameserver
Here's the address 93.184.216.34! ICANN
of the example.com s.______ example.com controls Canada
i^nameserver y nameserver this! controls this! I control this!
li-fe o? a DNS queru
want to go to
what's the IP for
. i®-"2 | v DNS cache o |_____
archive.org 207.241.224.2
https://example.com example. com?> jvns.ca 172.64.80.1

browser
nope, I don't have it
hmm, I don't have an IP cached, I need to ask the
hmm, I'll look in resolver authoritative nameservers!
address for example.com browser
my cache... resolver I have the root nameserver
cached. I'll ask a reso ver! IPs hardcoded. z

f note: we're pretending the resolver has no .com domains cached. Normally it would use its cache to skip step *t.

what's the IP -♦com NS a.gtld-servers.net.


ask a .com nameserver!
for example.com? ca NS a.ca-servers.net.
It's at a.gtld-servers.net
resolver ' horse NS^ a.nic.horse.
naneserver

NS stands for "nameserver'


list of DNS records
f ask an example.com.
what's the IP
nameserver! It's at neopets.com NS ns-42.awsdns-05.com.
for example.com? , a.iana-servers.net-> —►example.com NS a.iana-servers.net.
resolver ' .com nameserver

what's the IP -» example.com A 93.184.216.34


for example.com? it's 93.184.216.34! &

resolver 0 great, I'll tell the browser! example.com nameserver


DNS records
When you make DNS changes for your domain, you're editing a DNS record DNS records have 5 parts
Type Name (subdomain) IPv4 address
-» name (eg tail.examplecat.com)
A ▼ paw 1.2.3.4 Imin v
- » type (eg CNAME)
Use @ for root
-» value (eg tail, jvns.ca)
-» TTL (eg 60) /
Here's what the same record looks like with dig «------- wen explain
dig on page 18 -» class (eg IN) I
$ dig +noall +answer paw.examplecat.com different record types have different Kinds
of values: A records have an IP address,
paw.examplecat.com. 60 IN A 1.2.3.4
and CNAME records have a domain name.

name TTL record type


60 A
paw.examplecat.com
"time to live". How long to cache "A" stands for "IPv4 —Address".
When you create a record, *
the record for, in seconds.
you'll usually write just the
subdomain (like paw).
class value
When you query for a record, 1.2.3.4
IN
you'll get the whole domain
"IN" stands for "INternet". You can
name (like paw.examplecat.com). the IP address we asked for!
ignore it, it's always the same.
I literally mean everything, I copied this verbatim from a real DNS request using V/ireshark.
(DNS packets are binary but we're showing a human-readable representation here)

request --------- response -----------


Let's look at the
actual data being sent randomly matches
Query ID: 0x05a8 4----------- request 10
during a DNS query:
Flags: 0x100 Flags: 0x8580 4-----
these flags just
Questions: 1 mean "this is a Questions: 1 the response code is
encoded in the last 4
Answer records: 0 request" Answer records: 1
bits of these flags.
Authority records: 0 Authority records: 0 The 3 main response
Additional records: 0 Additional records: 0 codes are:
Question: -»NOERROR (success!)
Question: ■+NXDOMAIN (doesn't exist!)
Name: example.com Name: example.com' -•SERVFAIL (error!)
A is for IPv4
Type: A ---------- Address, other
Type: A ____
copied from
browser resolver Class: IN types: MX, CNAME, Class: IN request
AAAA, etc Answer records:
IN stands for
Name: example. com 4-.
domain names aren't
"INternet" Type: A case sensitive
Class: IN
TTL: 86400
the IP we
Content: 93.184.216.34 asked for
Authority records:
(empty)
Additional records: page 12 (“NS records'1)
talks more about these
(empty) 2 sections
■the toot nameservecs 10
every DNS resolver root nameserver IP there are thousands of
starts with a addresses almost physical root nameservers,
root nameserver but only 13 IP addresses
never change
Each IP refers to multiple
what's the IP a.root-servers.net's IP physical servers, you'll get
for example.com? (198.41.0.4) hasn't changed
resolver the one closest to you.
since 1993^ f^OE-CAOfs this is called
^You should ask a .com
nameserver! "They're at ====~ *8° I There's a map at ,,anMcast"
. a.gtld-servers.net. b.... https://root-servers.org
v —X.rnnt nameserver

a.root-servers.net 198.41.0.4
if they didn't exist, every resolver has the
b.root-servers.net 199.9.14.201
resolvers wouldn't Know root IPs hardcoded in its c.root-servers.net 192.33.4.12
source code d.root-servers.net 199.7.91.13
where to start e.root-servers.net 192.203.230.10
example: https://wzrd.page/bind f.root-servers.net 192.5.5.241
Here they are! •------------------------------ A g.root-servers.net 192.112.36.4
You can query one like this: h.root-servers.net 198.97.190.53
dig @198.41.0.4 example.com i.root-servers.net 192.36.148.17
j.root-servers.net 192.58.128.30
All the IPs will give you the exact k.root-servers.net 193.0.14.129
same results, there are just lots of 1.root-servers.net 199.7.83.42
them for redundancy. m.root-servers.net 202.12.27.33
your domain's aulhoriTat ive name servers
when you register a LOTS of services can be your how to find your
domain, your registrar authoritative nameserver
domain's nameservers
runs your authoritative
nameservers by default $ dig +short NS neopets.com
ITjl J I'm taking carel
ns-42.awsdns-05.com.
y^r of your DNSt^y
ns-1191.awsdns-20.org.
registrar
neopets.com is using AV/S's
You can change your nameservers
in your registrar's control panel. nameservers right now

how to change your why changing your what can go wrong if


nameservers nameservers is slow you don't delete the
QCopy your DNS records to the old records
_ 1 here's the new nameserver
new nameservers x f for example.com! I'll go to $OLD_NAMESERVER
(use dig to check that it worked) registrar x.____________ ______________ ‘ to change my DNS records!
(2) On your registrar's website,
ok great, I've saved this record:
update your nameservers WHY doesn't it WORK?!?!?
^example.com NS newns.com 172800,
©Wait 48 hours .com
o foh right, I changed this
(Ji) Deleft the old DNS records updates are VERY SLOW na"e9erver ? domain's nameservers r
(to save your future self confusion) because this TTL is 2 days (last year, oops!j-r-'
NS records
V/hat's actually happening when The root nameserver can return The NG record gives you the
the root nameserver redirects to two Kinds of DNS records: domain name of the server
the .com nameserver, on page 6?
NS records: (in the Authority section) to talk to next, but not its
what's the IP com. 172800 NS a.gtld-servers.net IP address. _
for example.com? com. 172800 NS b.gtld-servers.net
resolver f T t t But I need the IP for
name TTL type value
am not concerned with
a.gtld-servers.net to
petty details like that. glue records: (in the Additional section) communicate with it!
Here's the address of a.gtld-servers.net 86400 A 192.5.6.30
^the .com nameserver b.gtld-servers.net 86400 A 192.33.14.30 resolver is there a glue record?
C. this is an NS record root "a"eser''er name TIL type value

2 ways the resolver glue records help resolvers terminology note


gets the IP address avoid infinite loops
NS records are DNS records
without a glue record for with type "NS".
© If it sees a glue record
a.gtld-servers.net: disaster!
for a.gtld-servers.net, the Also, an "A record" means
resolver will use that IP what's the IP for "record with type A", " 1X recoi "
a.gtld-servers.net?) means "record with type ", etc.
@ otherwise, it'll start a resolver \
(confusingly, this is not true for
whole separate DNS lookup You should ask
glue records, glue records have
for a.gtld-servers.net a.gtld-servers.net
root nameserver type A or AAAA. It's weird, I know.)
subdomains 5 12
to make a subdomain, there are 2 ways a nameserver can
you just have to set handle subdomains
a DNS record! © Store their DNS records (2) Redirect to another
To set up cats.yourdomain.com, itself authoritative nameserver
create a DNS record like this in (this happens if you set an NS record for
your authoritative nameservers: the subdomain, it's called "delegation")
here's the IP for
cats.yourdomain.com A 1.2.3.4 cats.you rdoma i n.com! ask this other DNS
f T f server instead!
nam^, record typ-e- value.

you can create www is a common love using subdomains\


for my projects (like
multiple levels of subdomain dns-lookup.jvns.ca)
subdomains Usually www.yourdomain.com because they're free, I
and yourdomain.com point to can give a subdomain a
For example, you can ' different IP, and it
make: the exact same IP address. keeps projects separate,
If you wanted to confuse
a.b.c.d.e.f.g.example.com
people, you could make them
up to 127 levels is allowed! totally different websites!
whig DNS updates are slow- caching
You might have heard DNS records are cached let's see what happens
that DNS updates need in many places when you update an IP
time to "propagate". * browser caches
-
| bananas.com | | A ▼ | | 300 111.2.3.41
DNS resolver caches
What's actually I 4
—r operating system caches 60 | 15.6.7.81
happening is that there
are old cached records beware: even if you change the TTL
which need to expire. to 60s, you still have to wait 300
seconds for the old record to expire

30 seconds later... 400 seconds later... 12 hours later...


(you go to bananas.com in your browser) (you refresh the page again) (you check 1.2.3.4's logs to make
sure all the traffic has moved over)

that's weird, the old


server is still getting
a few requests...

I don't care about your


TTL! I just cache
*>r 24 hours!/the a
rogue DNS resolver
negative caching 15
I finally learned last resolvers cache
Here's a problem I've negative results
had many times year that my problem
was "negative caching" ^^/what's the IP
■“^Tfor bees.jvns.ca
I set up my new
domain, everything resolver fl don't have any 1—7 authoritative
o I records for that^T nameserver
looks good, but it's
not working?!?!
caching: no A records
for bees.jvns.ca

the TTL for caching negative results comes from the SOA record
example.com. (3600) IN SOA ns.icann.org. noc.dns.icann.org. 2021120741 7200 3600 1209600^600^)

it's the smaller of these 2 numbers (in this case 3600 seconds) —

what you need to know about SOA records how to avoid this problem
Q they control the negative caching TTL
Just make sure not to visit your domain
(?) you can't change them (unless you run before creating its DNS record! That's it!
your own authoritative nameserver)
(5)how to find yours: dig SOA yourdomain.com (if you really want more details, see RFC 2308)
resolvers can lie
When a resolver gets a DNS reason to lie: reason to lie:
query, it has 2 options: block ads / malware to show you ads
fl could tell you what the\ what's the IP fori
what's the IP for zzz.jvns.ca? J
f authoritative nameservers/
* doubleclick.net? .
_____ doesn't exist
\ said... or I could LIE! J ad domain,
definitely here's an IP that
o exists will show you ads!
resolver
PiHole blocks ads this way. This is called "DNS hijacking".

reason to "lie": airport DNS resolvers how does your


internal domain names sometimes lie computer know which
what's the IP for what's the IP for
resolver to use?
corp.examplecat.com?, google.com? When you connect to a network,
the router tells your computer
doesn't exist on the
______ public internet which search domain and
you didn't log in yet resolver to use (using DHCP).
here's an internal
so I will lie! here is airport
IP address! resolver: 1A2.168.1.1
our login page's IP! resolver search domain: lan
resolver router
(k tinu DNS resolver
* TE?3 IT-
___________________________________ ________(in Piyttion)________________________________

def resolve(domain): On page 5 (life of a DNS query),


# Start at a root nameserver ve sav/ resolvers work,
nameserver = "198.41.0.4" +. oniina +u;rW4
# A "real" resolver would check its cache here
while True: but ,+ ac+ua(ly dories,
reply = query(domain, nameserver)
ip = get_answer(reply)
if ip:
# Best case: we get an answer to our query and we're done
return ip
nameserver_ip = get_glue(reply)
if nameserver_ip:
# Second best: we get the *IP *address of the nameserver to ask next
nameserver = nameserver_ip
else:
# Otherwise: we get the *domain *name of the nameserver to ask next
nameserver_domain = get_nameserver(reply)
nameserver = resolve(nameserver_domain)
* Actual DNS resolvers are more can find +hc program7t>

complicated than this, but this \https://github.com/jvns/tiny-resolver/


is the core algorithm. I
let's meet 18
dig is my favourite tool for tiny guide to dig's full output
investigating DNS issues $ dig example.com
; «» DiG 9.16.24 «» +all example.com
;; global options: +cmd response code
I find its default output ;; Got answer: £
unnecessarily confusing, ;; -»HEADER«- opcode: QUERY, status: NOERROR, id: 27580
but it's the only standard ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
tool I know that will give ;; OPT PSEUDOSECTION: the answer to our
you all the details. ; EDNS: version: 0, flags:; udp: 1232 DNS query
;; QUESTION SECTION:
;example.com. IN A The ".'' at the end
means that example.com
$ dig +noall +answer ;; ANSWER SECTION: isn't a subdomain of some
example.com.86400 IN A 93.184.216.34 other domain (like it's not
means "Just show example. com. degrassi. ca).
;; Query time: 0 msec
me the answer ;; SERVER: 127.0.0.1#53(127.0.0.1)
This might seem obvious,
section of the DNS but DNS tools like to be
;; WHEN: Wed Jan 26 11:32:03 EST 2022 unambiguous.
response." It's a ;; MSG SIZE rcvd: 56
lot less to look at! ,
$ dig +noall +answer example.com
just the answer! so
example.com. 86400 IN A 93.184.216.34 much less overwhelming!
t t record content
name TTL
+spe
dig command line, argument's >
the basics: dig ©SERVER TYPE■ DOMAIN tip: put +noall +answer
in your -/.digrc
Examples: 130+11 oP+tonal
dig example.com This makes your output
1 default type: A more readable by default,
;dig @8.8.8.8 example.com
default server: from and you can always go
/etc/resolv.conf back to the full output
!dig TXT example.com
1 (on Linux) v*/ith dig +all.
!dig @8.8.8.8 NS example.com
1______________________________

dig +noall dig +short DOMAIN dig +trace DOMAIN

Hide all output. Only show the record content. Traces how the domain
gets resolved, starting
Useless by itself, but at the root nameservers.
; $ dig +short example.com ;
dig +noall +authority Will This avoids all the caches,
■ 93.184.216.34 I
just show you the "Authority" which is useful to make sure
section of the response. you set your record correctly.
aetaddrirvfo
One weird thing about DNS reason 1: many (but not all!!) ... and not using getaddrinfo
is that different programs programs use the function might give a different result
on a single computer can getaddrinfo for DNS lookups...
get different results for use getaddrinfop -♦the program might not use
the same domain name.
ping Q don't!) ^'9 /etc/hosts (dig doesn't)
Let's talk about why!
program ^function3 resolver So if you see an error message like
-►the program might use
"getaddrinfo: nodename or servname a different DNS resolver
^^
*
problem" <server) not provided...", that's a DNS error. (some browsers do this)

reason 2: there are you can have multiple glibc and musl getaddrinfo
many different versions getaddrinfos on your are configured with
of getaddrinfo... computer at the same time /etc/resolv.conf
f IP of resolver to use
the one in glibc ; # Generated byj NetworkManager:
For example on a Mac, there's
-» the one in musl libc your system getaddrinfo, but ! nameserver 19Z.168.1.1 :
-»the one in Mac OS you might also be running a ! nameserver fd13:d987:748a::1 ■
container that's using must. On a Mac, /etc/resolv.conf exists,
And of course, they all behave but it's not used by the system
slightly differently :) getaddrinfo.
search domains 2.1
In an internal network (like many DNS lookup functions the base domain is
in a company or school), support "local" domain names
called a "search domain"
sometimes you can connect
to a machine by just typing On Linux, search domains are
its name, like this: configured in /etc/resolv.conf
Example:
$ ping labcomputer-23
; search degrassi.ca ■
Let's talk about how that (server)
this^tells getaddrinfo to turn
works! (the function appends a base
domain degrassi.ca to the end) lab23 into lab23.degrassi.ca

getaddrinfo doesn't always search domains can avoid search domains by


use search domains make DNS queries slower putting a at the end
It uses an option called ndots
to decide. where's jvns.ca? Use http://jvns.ca. instead
of http://jvns.ca
! search degrassi.ca
okay, first I'll try
: options ndots
jvns.ca.degrassi. ca
this means "only use search
domains if the domain name this is silly but it l~J
contains less than 5 dot " can happen! getaddrinfo
TCP DNS
If you manage servers, DNS queries can use either large DNS responses
sometimes DNS just breaks UDP or TCP automatically use TCP
for no obvious reason
A UDP DNS response has to ^here's a UDP DNS queryT^
TCP DNS is an be less than 4046 bytes.
uncommon but VERY UDP is the default.
<sorry, my response^
annoying cause of TCP can send an unlimited is too big to fit in L—
DNS problems! Let's amount of data. It's only a UDP packet! get I
learn about it! used when UDP wouldn't work. ^the rest with TCP!J

u/hat's in a giant hov/ not supporting 2 reasons 'TCP DNS


DNS response? TCP DNS can ruin might not v/ork,
your day (7) some DNS libraries (like musl's
I've seen responses © your server is happily getaddrinfo) don't support TCP.
with hundreds of making UDP DNS queries This is why DNS sometimes
internal server IP breaks in Alpine Linux.
addresses (for @one day, the responses get
(5) it could be blocked by your
example when using bigger and switch to TCP
firewall. You should open both
@oh no! the queries fail! UDP port S3 and TCP port 53.
A I AAAA records B 13
there are two Kinds of A stands for IPv4 ddress in theory, the
IP addresses: Internet is moving
Example: 93.184.216.34
IPv4 and IPv6 from IPv4 to IPv6
AAAA stands for IPv6 AAAAddress
Every website needs an IPv4 joke, but This is because there are
Example: xma^t-rue
address. only 4 billion IPv4 addresses
2606:2800:220:1:248:1893:25c8:1946
(the internet has grown a
IPv6 addresses are optional. LOT since the 1480s when
it's called AAAA (H As) because
IPv6 addresses have Mx as many bytes IPv4 was designed!)

*
happy eyeballs using IPv6 isn't IP addresses
always easy have owners
If your domain has both an A
You can find any IP's owner
and an AAAA record, clients -►not all web hosts give you by looking up its ASN
will use an algorithm called an IPv6 address ("Autonomous System Number").
"happy eyeballs11 to decide
whether IPv4 or IPv6 will be -» lots of ISPs don't support (except local IPs like
faster. IPv6 (mine doesn't!) 192.168.X.X, 127.x.x.x,
10.x.x.x, 172.16.x.x)
* yes that is the real name
CNAME records (H 2H
there are 2 ways to set CNAME records redirect what actually happens
up DNS for a website every DNS record, not during a CNAME redirect
© set an A record with an IP just the IP
's the A record for www.cats.com?3
www.cats.com A 1.2.3.4
I like to use them whenever www.cats.com CNAME cats.github.io
possible so that if my web
@ set a CNAME record with a
host's IP changes, I don't okay, I'll look up
domain name the A record for
need to change anything! cats.github.io! authoritative
www.cats.com CNAME cats.github.io resolver
nameserver

rules for when you can use CNAME records some DNS providers have
workarounds to support
Q you can only set CNAME records on subdomains (like CNAME for root domains
www.example.com), not root domains (like example.com)

(5) if you have a CNAME record for a subdomain, that Look up "CNAME flattening"
subdomain can't have any other records or "ANAME" to learn more.

(technically you can ignore these rules, but it can cause problems, the
RFCs say you shouldn't, and many DNS providers enforce these rules)
MX records El 15
there are two important MX records tell you copy and paste
problems in email the mail server for your MX records
a domain
*you're probably using\
From: kermit@frog.com an email service like '
To: julia@example.com $ dig +short MX gmail.com
Fastmail/Gmail, so
5 gmail-smtp-in.1.google.com.
just copy the records

(T)Make sure the message


\ t they tell you to use I
priority server's domain name
gets to the right recipient.
This is what MX records
are for. tiny guide to SPF/DKIM/DMARC records
(5) Make sure the sender didn't SPF: list of allowed sender IP addresses
lie about their From: address. Example: v=spfl ip4:2.3.4.5 -all
This is what SPF, DKIM, and DKIM: sender's public key
DMARC records are for.
Example: v=DKIM1; k=rsa; p=MIGFMA0GCSqGSI.............
SPF/DKIM/DMARC are very
complicated but we'll give a DMARC: what to do about SPF/DKIM failures
tiny incomplete summary. Example: v=DMARC1; p=reject; rua=mailto:dmarc@example.com
"TXT records & more O 26
TXT records can they're often used to reasons to verify
contain literally verify that you own your domain
your domain -•to issue SSL certificates
anything
with Let's Encrypt
examplecat.com TXT "hello! I'm
-•to use Single Sign On
an example (SSO) for a service
cat!" ■
*to get access to Google/
(though they're usually ASCII)
Facebook's data about your
domain (eg search data)

they're also used for TXT records can some other record types
email security contain many strings CAA: restrict who can issue
(SPF/DKIM/DMARC) certificates for your domain
Each string is at most 256
should we create a DNS characters, and clients will PTR: reverse DNS -- map IP
record type for SPF? . concatenate them together. addresses to domain names
(look these up with dig -x)
You'll see this in DKIM records,
because they're usually more SRV: holds both an IP
(not a historically accurate summary
the design process for SPF records)
than 256 characters. address and a port number
"thanks Tor reading
As with everything, 1 think, the best way to learn more about DNS is to
experiment and break things. So this zine comes with a playground!
* » I I t > I I f I t f / , x

1 https://messwithdns.net ~
' 1 >! ! till I I ' ' ' X

More DNS tools I made while writing this zine:


https://dns-lookup.jvns.ca (to make DNS queries)
https://github.com/jvns/tiny-resolver (to see how resolvers work)

___________________ credits________
Cover art: Vladimir Kasikovic
Copy editing: Gersande La Fleche
Technical review: Ray Bejjani
Editing: Dolly Lanuza, kamal Marhubi
Pairing: Marie Claire LeBlanc Flanagan
Any remaining errors: mine <!>
* wizardzines.com ☆

You might also like