This post is largely based on these two great posts:

DNS is one of those things that I found unnecessarily mysterious and scary for too long. In retrospect, it feels pretty silly. Here’s my attempt to resolve the mystery of DNS.

DNS resolves domains like vercel.com into an IP addresses like 76.76.21.21.

What problem is DNS trying to solve?

To dissolve the mystery of DNS, we need to understand a bit about what a website is. A website is just computer program that’s running somewhere that, when asked, is willing to send back a bunch of HTML (probably along with some javascript and css). This is a really simple fact, but with all the modern fanciness of today’s web technologies (e.g. CDNs, “lambda functions”, “serverless”), I feel like it can get lost in the confusion.

The problem that DNS solves is: given a domain (e.g. google.com), how do I find the computer program that’s willing to send me the right HTML (and javascript/css)?

There are about 350 million different domains accessible via the internet (as of June 2022). Each one has (at least) one corresponding computer program associated with it. We need a way to find it.

Terminology

If you spend any time trying to google what DNS is, you’ll run into a bunch of terms which you might not be familiar with.

  • A host is just another name for a computer.
  • A server is used in two different ways (of course). Sometimes people use server to refer to a computer. Sometimes people use server to refer to a particular program running on a computer. For the latter case, web server is often used, which is a little more clear.
  • An IP Address is the address of a particular host. They look like this: 192.158.1.38 or 76.76.21.21. Here’s a helpful analogy: An IP Address is to a host what a mailing address is to a house. In both cases, the address is a way to locate the object in question (a host or a house). As with mailing addresses, IP addresses have a particular structure to them.
  • A domain is a user-friendly way of referring to an IP address. They look like google.com or vercel.com. Domains exist for a few reasons, but a big one is so that you don’t have to remember website URLs that look like 76.76.21.21. You can type vercel.com into your browser instead and, let’s be honest, that’s a lot easier to remember. Another nice reason is that, the location (IP address) of vercel.com might have to change from time to time. Maybe they used to run their web server on Heroku but later switched to an Amazon AWS host. When you change what host you use, the IP address changes (like how your mailing address changes when you move houses). It would be pretty painful if everyone had memorized the IP address of your Heroku host and then couldn’t find your website anymore when you moved to AWS. So, domain names serve as a nice level of indirection that insulates end-users from the nitty-gritty details of what hosts you’re using.

DNS resolves domains like vercel.com into an IP addresses like 76.76.21.21.

So simple! Unfortunately, not so fast. If you go buy a domain name and a host (on AWS, for example) and you go to configure DNS for your domain, you’ll see advice such as “You should use a CNAME record to point your www subdomain to your apex domain.”. Uhhh… what?

URL Structure

  • In the example above, the apex domain is acme.com. A single apex domain can have many subdomains associated with it.
  • A subdomain is what goes before the apex domain. In the example above, it’s docs. Other examples would be www in www.google.com or blog in blog.russelldmatt.com.

Why are subdomains useful? One reason is that is provides a way to organize your site. You can put some content in blog.russelldmatt.com and other content in shop.russelldmatt.com. But that’s not a great reason because you can provide organization in other ways, e.g. www.russelldmatt.com/blog vs. www.russelldmatt.com/shop.

The main reason (I think) is that you can point different subdomains to different IP addresses. That means shop.russelldmatt.com can use a completely different web server than blog.russelldmatt.com.

DNS Records

Here’s a great table describing the most common DNS record types.

To highlight the most important points:

  • A records map (apex) domains to IP addresses. For example, they might translate vercel.com into 76.76.21.21.
  • CNAME records points one domain (or subdomain) to another domain. They do not point domains to IP address. So, this record type is useful if you want to point your www.vercel.com subdomain at your vercel.com apex domain. It works as an alias for domain names that share a single IP address.

Putting this into practice

At this point, I think you could actually go configure DNS for a newly purchased domain name and probably not get confused.

To put this into practice, let’s configure the domain motivatingexamples.com (using GoDaddy) to point to a web server hosted by vercel. We will follow the instructions so nicely laid out here.

Using vercel’s website, I first select the project that I want to use for motivatingexamples.com and then click view domains.

Next we add our domain motivatingexamples.com to our project, like so:

Go to your GoDaddy account to manage your DNS. Navigate to your domain list. Select the domain you want to point to your vercel app.

In the Domain Settings, click on the Manage DNS link to configure your DNS. Configure an A record to point this domain at vercel’s IP address. Then, so that people can type www.motivatingexample.com and get to the right place, add a CNAME record that points the www subdomain to the apex domain motivatingexamples.com. Like so: