Table of Contents
- Question
- Response
- Solution #1 (Traditional CNAME)
- Solution #2 (CNAME Flattening)
- Question #2
- Answer #2
- Question #3
- Answer #3
Content Error or Suggest an Edit
Notice a grammatical error or technical inaccuracy? Let us know; we will give you credit!
Question
This question was on Facebook, and it’s needed a blog post 🙂
This is about CNAME flattening and references this Gridpane KB. https://gridpane.com/kb/dns-management-and-cnames/
This question is not GP specific so thought to try here instead of the GP forum.
In the example given above, CNAME at the client DNS ultimately points to clientname.yourdomain.com. This makes sense and works. Now I want to set this up for a subdomain.
To get a subdomain (ie.subdomain.clientdomain.com) to point to a GP server, is this the way to set things up?
At client DNS, setup CNAME = subdomain and point it to clientname.yourdomain.com
Then at yourdomain.com, setup A record for “subdomain” and point it to IP address of a GP server.
Then spin up subdomain.clientdomain.com at a GP server?
Something seems off as the “subdomain” would be set for subdomain.yourdomain.com. How does one setup DNS (on my end) to point subdomain.clientdomain.com to the actual IP on GP?
In short, access to client DNS is not easy so trying to setup DNS 1 time and update IP on my end as needed.
Any thoughts would be appreciated.
Response
First take out CNAME flattening for the time being, let’s talk about CNAME’s first.
How do CNAME’s work?
A CNAME points a DNS record, such as subdomain.clientdomain.com, to another named-based DNS record, which can be an A or CNAME record, such as subdomain.yourdomain.com
You create a CNAME record on your DNS provider, which can be the same as your Domain Name registration provider who also provides DNS service for free. They have nameservers that hold a zone of yourdomain.com with all your records, which are set on yourdomain.com as the “nameservers”. The nameservers will simply output the value of the CNAME subdomain.clientdomain.com to subdomain.yourdomain.com, and it’s the responsibility of the resolver (Dig, nslookup, Chrome, etc.) to resolve the subdomain.yourdomain.com
So the resolver (Dig, nslookup, Chrome, etc.) looks up subdomain.yourdomain.com which can be an A record pointing to 192.168.0.1 or another CNAME which points to subdomain.secondomain.com at which point the resolver (Dig, nslookup, Chrome, etc.) has to again look up subdomain.secondomain.com of which could be an A record or CNAME record.
CNAME Chaining
When a CNAME points to a CNAME, this is CNAME changing, which can chain up to as many DNS records as you wish. However, there is a cost because each resolution takes time and sometimes software will fail to go through the chain.
APEX Records @
Why are we talking about APEX records (@)? Because you can’t create an APEX record as a CNAME, as it’s against the DNS standard. There’s a good thread on stack overflow if you want to go deeper.
However, there is a workaround using CNAME Flattening.
CNAME Flattening
On to CNAME Flattening. What is CNAME Flattening?
CNAME
 flattening speeds upÂCNAME
 resolution and allows you to use aÂCNAME
 record at your root/apex domain (example.com
).With
CNAME
flattening, Cloudflare finds the IP address that aCNAME
points to. This process could involve a single lookup or multiple (if yourCNAME
points to anotherCNAME
). Cloudflare then returns the final IP address instead of aCNAME
record, helping DNS queries resolve up to 30% faster.For more details on the mechanics of
https://developers.cloudflare.com/dns/cname-flattening/CNAME
flattening, review the CNAME flattening diagram and refer to the Cloudflare blog postOpen external link.
As you can see CNAME flattening is important, and Cloudflare supports CNAME Flattening as do other providers in different ways. Why is it important to bring this up? Specifically, it’s important when you’re creating a CNAME and both domain names are set up on Cloudflare.
Cloudflare will flatten CNAME records, which interferes with how CNAME’s typically operate and you need to be aware of this.
Solution #1 (Traditional CNAME)
Let’s map this out in simpler terms.
- Client domain = clientdomain.com – Not on Cloudflare
- Your domain as the provider = yourdomain.com – On Cloudflare
Here’s the setup.
- Setup subdomain.yourdomain.com first as an A/CNAME record and make sure it’s not proxied in Cloudflare
- Then set subdomain.clientdomain.com as a CNAME to subdomain.yourdomain.com
So subdomain.clientdomain.com will point to whatever subdomain.yourdomain.com points to, and the client will resolve it. The request from the web browser still comes in as subdomain.clientdomain.com to the destination web server. So you will need to make sure that subdomain.clientdomain.com is setup on your webs server correctly.
Solution #2 (CNAME Flattening)
Taking the same data from Solution #1, you can do CNAME flattening at Cloudflare and save some time for your DNS record to resolve.
- Client domain = clientdomain.com – On Cloudflare
- Your domain as the provider = yourdomain.com – On Cloudflare or another DNS provider.
Here’s the setup.
- Setup subdomain.yourdomain.com first as an A/CNAME record and make sure it’s proxied in Cloudflare
- Then set subdomain.clientdomain.com as a CNAME to subdomain.yourdomain.com and make sure it’s not proxied at Cloudflare.
The above diagram will also work with APEX records, hence why I have the Resolve/Flatten. Depending on what is put in the web browser, if it’s an apex record or sub-domain, it will be resolved and flattened.
Question #2
Yes, will do that! btw, just so I know for future ref, once the cnames are setup to point to a final A record, the server with the actual subdomain.clientdomain.com account will sort out the final route to the destination site correct?
Answer #2
Correct, this is what happens.
Question #3
Also, will subdomain have to match at both DNSs?
And will subdomain.clientdomain.com gain the benefits of CloudFlare if yourdomain.com is proxied with the orange cloud? Hoping CF can still block xmlrpc and watch wp-login.php for subdomain.clientdomain.com. Fun stuff right?
Answer #3
Do CNAME records need to match to resolve properly?
I’m using CNAME records here instead of subdomains or domains because these are all DNS records at the end of the day. No, you don’t need to match a CNAME’s name to its value, such as
bob.domain1.com (CNAME) -> bob.domain2.com (A) 192.168.0.1 charlie.domain3.com (CNAME) -> srv01.domainabc.com (A) 192.168.2.1 john.domain4.com CNAME -> 3bn45bgv23456yc46252b456b7y5366uf5.domain5.com (A) 192.168.88.1
As you can see, all that matters is that your CNAME’s value is an A record that is already resolved. Although you can chain CNAME’s, it’s a bad idea for multiple reasons which are outside this article. Check out this article
Does a non-proxied DNS record absorb the Cloudflare protection of the DNS record it’s CNAME’d to?
Yes and No.
What happens to A non-proxied DNS record that has a CNAME to a Cloudflare proxied DNS record
The following happens when a non-proxied DNS record has a CNAME to a Cloudflare proxied DNS record.
- The web browser resolves the DNS record subdomain.clientdomain.com
- The record subdomain.clientdomain.com is not proxied and is a CNAME with the value of subdomain.yourdomain.com which is proxied.
- The web browser resolves subdomain.yourdomain.com to a Cloudflare IP.
- The HTTP request from the web browser will be sent to the IP address returned (Cloudflare IP), and the HTTP request will contain a Host header of subdomain.clientdomain.com, which is the name typed into a browser’s address bar.
- Cloudflare reads the host header, and a lookup will be done to see if the domain name, not the DNS name, is set up on Cloudflare.
This is where one of two things will happen.
If the domain is set up on Cloudflare, then it will process the request. However, if both domains aren’t in the same account you will get Error 1014 CNAME Cross-User Banned. Which
If the domain is not setup on Cloudflare then you will receive an Error 1001 DNS resolution error because Cloudflare doesn’t know what to do with subdomain.clientdomain.com
How do I protect a non-proxied DNS record with Cloudflare?
There are a couple of solutions.
- Move the domain name to Cloudflare and use Solution #2 (CNAME Flattening) above.
- Use Cloudflare SaaS, which is mentioned below.
- Become a Cloudflare Partner and use a Partial DNS Zone, however, be aware that the domain names DNS provider has to support CNAME flattening on the Apex record due to Cloudflare only providing named records for Partial DNS Zone setup and not IPs.
Addressing “Error 1014 CNAME Cross-User Banned” and Cloudflare SaaS
You could use Cloudflare SaaS to control 100’s of domains with a single Cloudflare configuration.