CNAME showing as A Record

I have a CNAME set in Cloudflare to point to my main host. But a dig on that cname results in it just showing the A record for the host, not the cname. It looks like this is breaking hosting since I’m being directed to the wrong site on my shared hosting (the web server isn’t seeing the host being requested, it’s just serving up the “default”.

Any thoughts?

That’s CNAME flattening, which is why many hosts that use this configuration insist you use www to reach your domain. Then you’d set a redirect on your naked domain to redirect to the www.

Regardless of what a DNS record points to the host header should remain unchanged that the client sends. This is what the virtual server should be configured to respond to. So if it is foo.example.com the webserver needs to know to serve the foo site (that the record ultimately pointed to an A record or CNAME is transparent to the webserver).

Great, it’s cname flattening… but something is breaking. Other cnames are working, and show properly. This one doesn’t. And yeah, the host should work, it’s not. I’m not positive this is the reason, but DNS is usually the culprit when things are wonky. Can I disable cname flattening for records?

seems to be partially working now, but still remains a question of if I can disable cname flattening. Is that option only for paid accounts?

I think it’s possible to disable it at the bottom of the DNS page (it’s all or nothing though). You can’t do so at root though, since the root domain can’t have a CNAME by rule.

I don’t get what that means. You’re saying you can’t have:

bar.com 1.1.1.1
foo.bar.com cname bar.com

Or are you saying that bar.com can’t be a cname of Cloudflare.com? (I know that one, Cloudflare has never let you do that).

No, example.com can’t be a CNAME to anything else.

You can’t have a response for a DNS request of a root domain like example.com be a CNAME. If you talk about a subdomain whatever.example.com then it can be a CNAME to example.com.

okay, that’s what I was understanding. It sounds like it’s also not best practice to have www.example.com be a cname of example.com

It doesn’t matter much, the remote host will listen to www.example.com and example.com regardless as during a CNAME the Host header remains the first one. Doing a CNAME (without the flattening or the CF proxy) incurs a DNS penalty for lookup. With the flattening (or proxy) it can be a way to reduce the duplication of IPs in the DNS settings.

okay. so then what’s the best CF practice?

Should I do:

www.staze.org cname staze.org
staze.org A x.x.x.x

Which would flatten, or should I do:

www.staze.org cname host.sharedhost.com
host.sharedhost.com A x.x.x.x

Which won’t.

Example of why the former worries me…

You need to have a record for example.com, that is a given.

It doesn’t change anything given your setup, since the flattening doesn’t change anything for the users and no one will actually see the CNAME. If flattening is off or proxying is off then the less CNAME the better probably.

I usually tend to do a resource as [purpose].[subset].[city code].[country code].example.com without any proxying with both IPv4 and IPv6 if present and then CNAME to that and proxy, if needed this second record.

If you want to minimise DNS lookups the best-practice would be neither, but rather:

staze.org A x.x.x.x
www.staze.org A x.x.x.x

If you want to make management easier because your naked domain and www subdomain always point to the same host then my preferred approach is:

staze.org A x.x.x.x
www.staze.org CNAME staze.org

The article you linked to regarding why your formerly quoted approach of:

www.staze.org cname staze.org
staze.org A x.x.x.x

is worrying you is moot - in that configuration you don’t even have a CNAME at your root/naked domain level only on your www domain. The second example you quote:

www.staze.org cname host.sharedhost.com
host.sharedhost.com A x.x.x.x

would work but necessaites you having access to the DNS records for sharedhost.com and still doesn’t touch your initial isue of how do you get your root/naked domain to point to your host (as you’ve not even got it defined.

I would add that Cloudflare CNAME flattening is fine and dandy if you did want a CNAME at root. I’ve never known it create any issues.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.