Adding both CNAME and TXT DNS records for one subdomain
Solution 1
You can't. As RFC1034 says in s3.6.2,
If a CNAME RR is present at a node, no other data should be present
If you want a TXT
record for (say) www.example.com
, you can't have a CNAME
for www.example.com
, and will have to find another way to achieve what you want. This may mean monitoring example.herokuapp.com
yourself, and when the IP address changes, updating your own A
records for www.example.com
.
Solution 2
A workaround would be to use an ALIAS
record if your registrar supports it. It is a type of records that provides CNAME-like behavior on apex domains. Read more: https://support.dnsimple.com/articles/alias-record/#whats-an-alias-record
For example, you could create an ALIAS
record for @
which points to myapp.herokuapp.com
. This would allow you to also have TXT
records for @
on the same domain name.
Related videos on Youtube
serge1peshcoff
Updated on September 18, 2022Comments
-
serge1peshcoff almost 2 years
I have a Heroku app and I need to set up a domain for it. The common way to set it up is to use CNAME record to specify that this domain is an alias to
<your-domain-name>.herokuapp.com
. The thing is, I also want to add Google Webmasters and Yandex.Metrika integrations and the easiest way is to add two TXT record for the domain. I set it up like that:I need to have 2 TXT records on http://www.cscombo.com, but apparently this won't work because of this: https://stackoverflow.com/questions/34613083/cname-and-txt-record-for-same-subdomain-not-working
My current setup isn't working properly, because adding http://www.cscombo.com to the Google Webmasters wouldn't work (because TXT record for the www subdomain doesn't exist), and adding http://cscombo.com (non-www version) will work (the TXT record for this subdomain exists), but this way Google Webmasters won't be able to read both
sitemap.txt
androbots.txt
(because they both redirect to the www version of the site). The same story with Yandex.Metrika.So, the question: is there any way to add CNAME and TXT records for the same subdomain?
-
Tim over 7 yearsThe obvious answer is not to use a wildcard CNAME.
-
-
Patrick Mevzek over 3 years
ALIAS
is not defined by any standard, this is created by some providers, and called differently eitherALIAS
orANAME
orAPEXCNAME
or whatever else. -
David Backeus over 3 yearsI would challenge this. Doesn't the word "should" indicate a recommendation here rather than a hard law? In what scenario would there be any practical real world issue with a TXT record coinciding with a CNAME? I've personally added TXT records to hostnames containing CNAME's without any problems.
-
MadHatter over 3 years@DavidBackeus famously, one should be conservative in what one sends, and generous in what one accepts. You're right that it often doesn't cause problems to publish such records, but sometimes it does, and they can be unpredictable, and difficult to diagnose. Why set yourself up for Heisenbugs?
-
Tenders McChiken over 2 yearsNot only by some providers.
ALIAS
is supported by PowerDNS, an alternative to bind9, which is available in both Ubuntu's and Debian's official repositories. Also, since ALIAS is purely server-side, it doesn't have to be defined by any standard, fortunately.