Skip to Content
Navigation:

A stick figure smiling

Here's a preview from my zine, How DNS Works! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
read the transcript!

On page 5 (life of a DNS query), we saw how resolvers work. This code does the same thing, but it actually works.

def resolve(domain):
# Start at a root nameserver
nameserver = "198.41.0.4"
# A "real" resolver would check its cache here
while True:
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 complicated than this, but this is the core algorithm.

Smiling stick figure with curly hair: You can find the whole program at https://github.com/jvns/tiny-resolver

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)