CNAME Flattening for Web Agencies
CNAME Flattening for Web Agencies
The acquisition of Cloudways by Digital Ocean stirred up quite a few conversations about how challenging it can be to migrate websites to a new server or platform. Justin Korn shared a fantastic post in The Admin Bar Facebook Community explaining how he uses CNAME Flattening to manage all that mess.
I’ve been using CNAME Flattening for a long time in pretty much the same way he described, and I was surprised to see that this concept was new for so many people. A text write-up of CNAME Flattening can get a little complicated, so I thought I’d do a quick video to help describe it.
This video assumes that you have a basic understanding of DNS concepts. If you need a refresher, you can visit my blog post called Domains & DNS Definitely Demystified, which lays the foundation for you.
- Domains & DNS Definitely Demystified – DNS Primer Video and Post
- Introducing CNAME Flattening: RFC-Compliant CNAMEs at a Domain’s Root
- How Does CNAME Flattening Work? | DNS Made Easy Blog
As Agencies, we manage a lot of websites. And all those websites have their own individual set of DNS servers and DNS records. We also might not have access to all the DNS servers. A lot of times, clients will manage them themselves, or they’ll have their IT departments and vendors handle it for them. Moving websites between servers can also be a logistical nightmare for all of us.
A Simple Solution
A simple solution to all of this is called CNAME flattening. Some other places call these ANAMEs or ALIASs, but really what it does is it lets us use a CNAME record to get the root IP addresses for a domain from a different domain. That lets us control all our client’s host records from a domain that we control, and it allows your clients to maintain control over their own DNS servers while we manage the website-related records on our own servers.
For this to work, though, both your DNS server and the client DNS server have to support this. Some of the big-name DNS servers that do support it are Cloudflare, DNS Made Easy, DNSimple, Easy DNS, and Amazon. Unfortunately, places like GoDaddy and Google domains do not support it.
If you’re interested in the technology behind all of this, there are some great resources out there. Cloudflare has a blog post called Introducing CNAME Flattening: RFC-Compliant CNAMEs at a Domain’s Root, and DNS made easy has a blog post called How does CNAME flattening work? I definitely recommend checking both of those out.
How to Configure CNAME Flattening
So to set this up, you would need to do things on both your server and the client’s server. On your server, you start by creating a dummy domain, something like myagencyrecords.net, and this is what’s going to hold all the records for your clients and for your servers. Then, you’ll create ANAMEs which are host records for your servers. Things like server1.myagencyrecords.net will point to 184.108.40.206, etc. Then you would create CNAME alias records for each of your client sites. Something like client1 one would point to server1.myagencyrecords.net, client2.myagencyrecords.net would point to server1.myagencyrecords.net, etcetera, etcetera until you have all of your clients on there pointed to the CNAME records for all of your servers.
On the client side, you want to make sure that you delete the A record for the root domain. In this example, the A record for client1.com would be deleted. Then you would create a new CNAME record for that root domain, and you’d point the CNAME to the client record that you created on your server. For example, you might point client1.com to client1.myagencyrecords.net. Look very carefully, though, that you point that CNAME record to the client record on your server, not the server record. I’ll get to that in a minute.
The last thing you want to do is make sure that the WWW CNAME record points to the root domain. This just keeps you from having to manage yet another record since most times, that WWW CNAME name is going to go to the same place as the root domain.
How does this work?
Let’s see how all this works in practice. We start off by wanting to go to client1.com. Client1’s DNS server is going to respond and say, “Hey, I see a CNAME record for client1.com. It points to client1.myagencyrecords.net. Let’s get you an IP address for that.” Then the Client1 DNS server says, “Hey, myagencyrecords.net, What’s the IP address for client1.myagencyrecords.net?” Myagencyrecords.net’s DNS server comes back and says, “Cool, I have CNAME for this, and it points to server1.myagencyrecords.net, and the IP address for server one is 220.127.116.11.” Client1’s DNS server then gets that IP address and says, “Awesome! I got that!” and it tells the client, “Hey, I talked to everybody, and here’s the address you’re looking for.”
Looking up a Flattened Record
Put another way, to get the IP address for client1.com; you’ll start off by getting that CNAME for client1.myagencyrecords.net. That CNAME points to another CNAME for server1.myagencyrecords.net. And that server record points to an A record that says 18.104.22.168. The CNAME flattening process just flattens all those steps so that client1.com can get that IP address of 22.214.171.124.
And for the next part of that, to resolve the WWW, you’re just getting that CNAME record for www, and it’s saying, “Hey, the IP address for this is the same thing as the IP address for the root domain.”
Questions & Answers
So here are a few questions and answers about the whole thing.
- Q: Can’t I just point the CNAME for client1.com to an A record on myagencyrecords.net?
- A: Yep. You can do that, and it’ll work just fine. The downside is that you’ll have tons of duplicate A records to manage. The CNAME that points to the server lets you change an IP address in one place and have it reflected for all clients that are using that server.
- Q: Does this slow things down?
- A: The performance hit is negligible, especially compared to all the other things happening. Besides, chances are that the servers that support CNAME Flattening already have most of this cached anyway.
- Q: I’m getting a Cloudflare Error 1014: CNAME Cross-User Banned. What’s that?
- A: Flattening is seamless when both client and agency records are on the same Cloudflare account. If they are on separate accounts, you may need to use the (paid) CloudFlare for SaaS addon.
- Q: Does this work with CDNs?
- A: You’ll have to check your specific DNS servers. I have successfully used it with DNS Made Easy and QUIC.Cloud but most of my clients use Cloudflare so I haven’t tested it with too many providers.
I hope this was helpful, and if you have any questions, don’t hesitate to reach out to me. You can find me on the web at www.peakperformancedigital.com.
Pinegrow Countdown: Day 5 – Desktop or Plugin?
With Pinegrow’s Black Friday sale and the WordPress plugin being released on December 1st, you might be asking yourself which product is right for you. I can’t answer that question for you, but I can help you think through some of the pros and cons of each one and why you might want to use […]
Pinegrow Countdown: Day 6 – What’s New
Pinegrow revealed that they would be releasing both the Pinegrow WordPress Plugin and Pinegrow Desktop 7.0 next week on December 1st. In this video, I share some of the new features in both versions, and I’ll talk a little about pricing and the Black Friday / Cyber Monday sale.
WP Tavern Interview on Building Websites With Pinegrow’s New WordPress Plugin
Last week I had the pleasure of being interviewed by Nathan Wrigley for the WP Tavern podcast. We talked about the upcoming Pinegrow WordPress plugin and how it lets my agency build custom, native WordPress blocks and themes for my clients. #51 – Adam Lowe on Building Websites With Pinegrow’s New WordPress Plugin
Peak Performance Digital: Agency Introduction (November 2022 Update)
This video presents information about my company, Peak Performance Digital. I cover the basics of who we are, what we do, how we operate, and what you can expect when working with us. This video is for companies who might want to hire us to work for them, or agencies who are looking for a white label partner.
WordPress Menu Accessibility – Part 2: Detailed Requirements and Final Test
In this video, I do a deep dive into the requirements to make an accessible Website Navigation Menu. I test the newly released Twenty Twenty-Three theme in WordPress 6.1 and show you the specific test criteria as I go along.