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.cominto an IP addresses like
What problem is DNS trying to solve?
The problem that DNS solves is: given a domain (e.g.
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.
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:
188.8.131.52. 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
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
184.108.40.206. You can type
vercel.cominto 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.commight 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
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?
- 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
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.
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
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
- 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.comsubdomain at your
vercel.comapex 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
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: