How Does CNAME Flattening Work?

CNAME flattening allows you to create a CNAME record at the root of your domain without violating RFC’s (the rules that govern the Internet).

Here at DNS Made Easy, we call these ANAME records… but we’ll get to that in a minute.

How CNAME Records Work

CNAME records point an FQDN (Fully Qualified Domain Name) to a hostname (like www.mydomain.com). Essentially, they act as an alias for other domains names. That’s why they are commonly referred to as “canonical”.

CNAME records are commonly used to point a domain to cloud services, like a CDN or DDoS protection. These services are almost always identified by hostnames because they constantly change which IP address they resolve to.

Let’s say you are browsing to a website that is hosted on a CDN. When you query the domain, you will most likely be answered by a CNAME record that returns the hostname of the CDN service. Something like ahsjfkd.www.mycdn.com. The CDN then determines which web server is closest to the user and returns the IP address of that server.

Since the IP could be different for each user, it’s more practical to use a CNAME record. But, CNAME’s can only be used on subdomains, like “www”.

That’s fine for most people, but the biggest trend lately has been the “naked” domain which is a regular URL just without the preceding www.

Go ahead a try it in your browser right now. Try to go to www.<domain goes here>.com and see what happens. It most likely changes the URL to https://<domain>.com.

Now, there isn’t anything stopping you from using a CNAME record at the root… It’s just bad practice because you can only have one CNAME record with the same name. Meaning you could only point the root of your domain once, which limits the number of cloud services you can point your domain to.

The Solution is ANAME

As we saw earlier with the CDN example, if you follow a hostname as it resolves, you will always wind up at an IP address or set of IP addresses.

So when you create an ANAME record in DNS Made Easy, you’re actually creating a dynamic A record.

Did I just blow your mind or what? 🤯

How It Works

DNS Made Easy caches the IP address(es) that the hostname resolves to and creates A record(s) with it.

Now we already know that the IP(s) are expected to change, so DNSME will continue to monitor where the hostname(s) resolves to. When it changes, it will automatically update the value of the A record(s).

Since ANAME records are able to skip all those extra hostname resolutions in between, they actually reduce resolution time!

You can even combine them with other ANAME records or regular ole A records. Just create multiple ANAME records with the same name (blank) but different hostnames. When the root is queried, DNS Made Easy will return each of the ANAME or A records in a round robin configuration.


Originally published at DNS Made Easy Blog.