DNS Record Crash Course for Web Developers
Tags: webdev, devops, dns
Published: 2019-10-29 11:19:50

*This was originally posted as a twitter thread: [https://twitter.com/chrisachard/status/1188870256971915265](https://twitter.com/chrisachard/status/1188870256971915265)*


Confused by DNS Records? A, CNAME, ALIAS...

Me too 😬 

Let's change that! (cheatsheet at the end)

🔥 DNS Record crash course for web developers 👇



# 1.

To get to `www.example.com`, your computer needs to know where on the Internet that server is

That means: it has to know what IP address to talk to

The way it finds out is the Domain Name System (DNS)

![DNS diagram](https://thepracticaldev.s3.amazonaws.com/i/o60vlffckjreoux3q8p3.png)


# 2.

When you register a domain, you can set many types of DNS Records

Each record has a Type, a Host, and a Value

- "Types" are predefined
- "Host" represents the root (`@`) or a subdomain (`www`)
- "Value" is an IP or web address, or other value

![DNS records type, host and value](https://thepracticaldev.s3.amazonaws.com/i/pmhvmi1bfavxw65h37zh.png)


# 3.

The `A` record maps a subdomain to an IPv4 address

This is most commonly used at the root, so it tells your browser where `example.com` lives

The `AAAA` record does the same for IPv6

![DNS A records](https://thepracticaldev.s3.amazonaws.com/i/46bx3zbixp0ul68iukvb.png)


# 4.

`CNAME` maps a subdomain to another domain name

This can be another subdomain on the same site (like forwarding www to the root)

or another domain like heroku - where your app lives

![CNAME DNS Record](https://thepracticaldev.s3.amazonaws.com/i/wgcbnpn19mzjs635ntdg.png)


# 5.

But there's a problem with `CNAME`!

Once you define a `CNAME` record for a subdomain (host), you CAN'T DEFINE another record for that same subdomain

Because of this, you can't use `CNAME` at the root level (where you need other records to exist)

![Don't use CNAME at the root](https://thepracticaldev.s3.amazonaws.com/i/5vecxhflnsvemjzfpmna.png)


# 6.

To fix that, `ALIAS` is used (sometimes `ANAME`)

`ALIAS` is like `CNAME`, but it's a non-standard dns type

So you can use `ALIAS` to forward your root domain (`example.com`) to your app's server (`example.herokudns.com`)

![Use ALIAS at the root of the domain](https://thepracticaldev.s3.amazonaws.com/i/cvyrzccpi5pfbdaq3vu3.png)


# 7.

That lets you put other records at the root, like:

`TXT` records, which provide extra info to any computer reading the DNS record

`TXT` records are often used to prove you own a domain - because only the domain owner can set a DNS record.

![TXT Record information](https://thepracticaldev.s3.amazonaws.com/i/sqkjftx3dradhs6rc69m.png)



# 8.

Or:

`MX` records (Mail eXchange), which you use to specify another server that handles your email (like google)

`MX` records are unique because you can set multiple servers that are each given a "priority"

![MX Records](https://thepracticaldev.s3.amazonaws.com/i/ovxdcaxh6qssqhrmzuyy.png)


# 9.

There are many other record types, but those are the ones you'll most often set yourself.

For each record, you also specify a Time To Live (TTL)

This tells DNS servers how long to cache your DNS values

![TTL determines cache](https://thepracticaldev.s3.amazonaws.com/i/yp5ou5rbusvgh2dniyt2.png)


# 10.

TTL is why it can take some time for your new domain records to "propagate"

DNS servers, your ISP, and even your own computer can cache DNS records, serving up the "old" values until the TTL runs out

![DNS Cache](https://thepracticaldev.s3.amazonaws.com/i/jk9x11hml6s3f7qrnxzj.png)


# Cheatsheet

Hopefully that made DNS a bit less confusing for when you set up your next domain!

To put it all together, here's a PDF cheatsheet of this crash course: [https://chrisachard.com/cheatsheets/dns-cheatsheet.pdf](https://chrisachard.com/cheatsheets/dns-cheatsheet.pdf)

🎉



&nbsp;

**Like this Post?**

You can find more on twitter: [@chrisachard](https://twitter.com/chrisachard)
Or join the newsletter 📬 [https://chrisachard.com/newsletter/](https://chrisachard.com/newsletter/)

Thanks for reading!