Skip to Content

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!

panel 1:

One weird thing about DNS is that different programs on a single computer can get different results for the same domain name.

Let’s talk about why!

Illustration of a program, represented by a box with a smiley face, and a resolver (server), represented by a box with a smiley face holding a magnifying glass. Between them is a function, represented by a rectangle with squiggly lines on it. There are arrows going back and forth between the function and both the program and the resolver (server).

The function is the problem.

reason 1: many (but not all!!) programs use the function getaddrinfo for DNS lookups…

ping, represented by a box with a smiley face: I use getaddrinfo! dig, also represented by a box with a smiley face: I don’t!

So if you see an error message like “getaddrinfo: nodename or servname not provided...”, that’s a DNS error.

and not using getaddrinfo might give a different result

  • the program might not use /etc/hosts (dig doesn’t)
  • the program might use a different DNS resolver (some browsers do this)

reason 2: there are many different versions of getaddrinfo

  • the one in glibc
  • the one in musl libc
  • the one in Mac OS

And of course, they all behave slightly differently :)

you can have multiple getaddrinfos on your computer at the same time

For example on a Mac, there’s your system getaddrinfo, but you might also be running a container that’s using musl.

glibc and musl getaddrinfo are configured with /etc/resolv.conf

IP of resolver to use

# Generated by NetworkManager
nameserver fd13: d987:748a::1

On a Mac, /etc/resolv.conf exists, but it’s not used by the system getaddrinfo.

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)