7 ms·
Why it's a bad idea to put a CNAME record on your root domain
- lingben 13y agovery happy client of DNSmadeeasy, imho the best DNS provider bar none, they were the first to have ANAME records: http://www.dnsmadeeasy.com/services/aname-records/ http://www.dnsmadeeasy.com/services/aname-records/
- eli 13y agoI found them to be kinda expensive at moderate scale. But maybe I was doing something wrong.
- rgj 13y agoThis actually makes sense, since the CNAME does not only replace A records, but any record. Not just MX but your NS and SOA records as well. Much less intuitive is the fact that a MX record cannot refer to a record that is a CNAME itself. http://www.exchangepedia.com/blog/2006/12/should-mx-record-point-to-cname-records.html http://www.exchangepedia.com/blog/2006/12/should-mx-record-p... Many soho routers performing DNS forwarding give very weird and unpredictive results if you do this.
- lamby 13y agoNeat. I'd always filed the "CNAME screws with MX" away in my mind but I never knew the underlying reason beyond "because the RFC says so and it doesn't work IRL".
- joshstrange 13y agoYeah, neither did I, I just assumed it was just a rule no one followed.... As you can see I was wrong. I'm just glad I finally tracked down the issue before it drove me crazy.
- colinbartlett 13y agoDNSimple has a similar service that lets you create a CNAME-like record for your root domain.
- joshstrange 13y agoThanks! I'll have to check that out.
- cooperx 13y agoI came here to add this exact statement. DnsMadeeasy is terrific and one of e few that support ANAME records
- toomuchtodo 13y agoUsing AWS' A record ALIAS concept does away with this problem. It does mean you have to use Route 53 though. Alternatively, use an ALIAS record for your apex (domain.com) that is an S3 bucket that redirects to www.domain.com (which you'd proxy through Cloudflare). EDIT: The ALIASing that Amazon does are internal health checks that are abstracted away. In the event of a failure, Amazon will update the A record with a new functional IP route extremely quickly (or rather, that's how its supposed to work). Also, you aren't charged for ALIAS queries, while you are for CNAME queries (which can add up depending on your traffic).
- joshstrange 13y agoYes, I don't go into detail in the blog but I link to the AWS Blog where they explain how to do just that. I didn't know about the health checks that's quite nice!
- lnanek2 13y agoA problem with heroku as well, not just Amazon.
- workhere-io 13y agoIt's not an Amazon problem, it's a limitation in the DNS specs.
- kelnos 13y agoIt's not really a limitation, per se. It's intentional behavior. Most people just use CNAMEs to as a sort of "A record redirect", but really they're for all records. You're saying "the canonical name for foo.com is blah.bar.com", and that means for everything: A, MX, NS, SOA, etc.
- joshstrange 13y agoYes, Heroku was another "culprit" of this kind of behavior that I would guess many people fall prey to. The worst part of it is how you will get some/most emails and some will just fall through the cracks. Unless you have a case like mine where you know an email should be coming and it's not then you can easily not know this is happening and be dropping emails.
- erikcw 13y agoI'd love for CloudFlare to add the equivalent of an ALIAS record to their DNS service. To the best of my knowledge one cannot use Route 53 and also take advantage of CloudFlare's services.
- joshstrange 13y agoYes, unfortunately I had to choose between the two. I like CloudFlare a lot but without that I was unable to stay.
- huslage 13y agoRFC anyone??
- nailer 13y ago+1. Hosted services shouldn't let people create behaviour that's outside the spec - I know dnsimple actively prevents people who try and attempt this.
- ddunkin 13y agoNot only that, but it trains people who don't read RFCs (or run DNS servers) to believe that configuration is even acceptable in the first place.
- crooksey 13y agoThe correct way todo this is setup a load balancer, then use route 53 to manage the dns, set the root domain to your load balancer I'D then map the www cname to the root domain, this solves all problems and takes under 5 minutes to configure.
- jakobe 13y agoTLDR: CNAME doesn't just forward A records, but MX records and others as well.
- ghayes 13y agoThen couldn't you then add your MX records under 'www' and all will be well? Does this affect DKIM?
- akerl_ 13y agoExcept if you add the MX records with a hostname of "www", they'll be used for emails to "your_name@www.example.org", which is generally not the desired behavior. And that still doesn't solve the issue with SOA/NS records, which need to exist at the root and thus will still conflict with the CNAME.
- deleted 13y ago[deleted]
- blueskin_ 13y agoIt shouldn't affect DKIM as that gives a specific subdomain, which is always prepended to the root domain to get the key.
- larrys 13y agoJust verified that this is not the case with dns records done through the domain manager at mediatemple.net May be the case elsewhere (just no time right now to test this). I would have started this reply by saying "not true" but don't know if the particular dns manager at mediatemple.net is setup in a way to be not compliant with the RFC. Update: Upon further testing it does return a MX record but can't resolve the host name for the MX record.
- eli 13y agoIt's really not a good idea. The issue isn't just whether mediatemple lets you do it... it's whether every DNS server that needs to talk to your domain understands it (and they don't).
- workhere-io 13y agoThe article points to an AWS article on how to set up the whole thing correctly - but once you've done that, there's still another problem: You really shouldn't host public stuff with S3 at all, unless you use CloudFront in front of it. Try benchmarking it with Apache Bench: S3 is extremely slow, whereas CloudFront is fast and can take a large number of hits.
- vertis 13y agoAs other people have noted, the solution to this is quite simple. Several DNS hosts support using an ALIAS record. The ALIAS record is then replaced with an A record when actually queried. Not sure which other companies support it, but http://dnsimple.com http://dnsimple.com does.
- sneak 13y agoI'm surprised that so many of the comments in this thread are about dns hosting services and not dns server software support for these so-called "alias records". I was making a list of "why on Earth doesn't this simple software exist?" items the other day and "simple server-side CNAME support" was on the list. Does any common DNS server package provide this support easily out of the box? It seems like one of the most common uses cases possible.
- axiak 13y agoA lot of DNS providers provide "ANAME" records. Which are essentially services which do the lookup and update A records in a cron.
- t0mas88 13y agoSmall warning: CNAME at apex is commonly used for pointing traffic to a CDN or load balancing kind of service. These services tend to use DNS for part of their traffic orchestration (e.g. different DNS response based on user region) which gets less than optimal or even plain wrong results if your DNS server software resolves the CNAME instead of the end-user. If they weren't using DNS as part of their strategy they could've given you a simple IP instead of a CNAME, saving your clients some lookup time.
- joeframbach 13y agowww.domain.com and domain.com should not just silently duplicate the same content. If you want one to be "canonical", then the other should respond 301 Moved Permanently with the correct address. Duplicate content across domains is a mess for SEO.
- dav- 13y agoSo, I have a question: Would the following be safe? Specifically the "* CNAME @" rule. https://gist.github.com/dav-/eaa487032588efc0b4a3 https://gist.github.com/dav-/eaa487032588efc0b4a3
- joshstrange 13y agoI'm fairly certain that is fine, it's not "on the root" because it's *.root.com not root.com, you have an A record on the root which is expected and correct.
- dav- 13y agoRight, thanks. I'm always paranoid that I may be missing emails.
- gore90- 13y agoIn my head I just think of 301'ing to the naked domain but that is only about web. What is the end goal of redirecting the domain with dns records like this? (Newbie)
- nmjohn 13y agoI'm a little confused by why this was even an issue. Why couldn't he just setup an A record for both domain.com and www.domain.com, and in his apache/nginx/pick your server config file 301 redirect www.domain.com to domain.com. Is that not the best practice?
- shaggy 13y agoYes it is and has been for a long time. What this article really boils down to is a terribly poor understanding of how DNS works and why certain records are use for certain serivces. A CNAME doesn't "redirect" anything at any level outside of a resolver. In the case of www.example.com and example.com you use a web server to achieve the desired result. Even then it's not a redirect, it's a replacement the resolver determines the record is a CNAME, inserts the value the CNAME points to, then resolves the A record. In the case of the MX record for a domain a CNAME is a problem because in the absence of a MX record, the A RR record is used, in this case a CNAME. Would protocol specific SRV records be better? Yes, but since that change isn't happening quickly do what's right now and change in the future.
- kelnos 13y agoBecause he's not self-hosting his website. He's using a S3 bucket, and the "normal" way of doing that is to CNAME to a S3-owned hostname, so Amazon can then mess with the IP address behind the scenes without telling you to update your A record.
- TuxLyn 13y agoI've always used only one "A" record for main domain like "domain.com" then everything else goes throught "CNAME", like "www.domain.com" or any oher sub-domain like "blog.domain.com" then have sepeate "MX" record for email. In Nginx I redirect useless (www) to (non-www) using permanent redirect (301) Never had any problems both with CloudFlare and NameCheap ^_^
- inopinatus 13y agoWe should not be using A records for websites. I'm hoping HTTP/2.0 will drag itself into this century and commit to using SRV records or something very like them instead, so that problems like this can go away with a general solution. See: https://github.com/http2/http2-spec/issues/381 https://github.com/http2/http2-spec/issues/381
- himangshuj 13y agoexact same thing happened to me for sokratik.com and www.sokratik.com, i solved it using nginx root /usr/share/nginx/www; index index.html index.htm; server_name sokratik.com; return 301 $scheme://www.sokratik.com$request_uri;
- joshstrange 13y agoYeah if I was running a server I would have done that in a heartbeat but I was using S3 so I was a little more limited.
- js2 13y agoBefore Amazon introduced the ALIAS record the workaround I had in place was a cronjob which queried for the A records of our Amazon ELB and replicated those to the root of our domain, which at the time was hosted with DNS Made Easy. It was an easy decision to move to Route 53 once the ALIAS record was introduced and retire my hack.
- eastdakota 13y agoHi: I'm the co-founder and CEO of CloudFlare. This can be a problem with some mail servers (especially Exchange, in our experience). Good news is we have a solution. We have a feature called CNAME Flattening which dynamically turns a CNAME at the root into an IP address. This solves the issue. We've beta tested this for the last few months and it works great. We haven't exposed in our UI yet but if you write to our support team we'll enable it. We're offering it to all our customers, even as the free tier. We plan to roll it out in our UI soon. Functionally, it's very similar to services that have an "Alias" record without requiring users to learn a new, non-standard DNS record type. Matthew Prince (@eastdakota) Co-founder & CEO, CloudFlare
- xxdesmus 13y agoFor those curious to see CloudFlare's CNAME flattening in action (it's seamless, so it's not sexy to look at though): https://gist.github.com/xxdesmus/9202356 https://gist.github.com/xxdesmus/9202356 root and WWW for shiftyplatypus.com are both CNAMEs (pointing at Heroku).
- colmmacc 13y agoThe problem doesn't have much to do with particular mail servers, but rather with the order in which queries may be made. Let's say the following two records are allowed to co-exist: example.com 60 IN MX mail.example.com example.com 60 IN CNAME foo.example.org and that the MX record takes precedence over the CNAME when queried. Imagine a client, C, behind resolver R, and it makes the following queries; 1. C looks up qname=example.com qtype=MX, R returns the MX record 2. C Looks up qname=example.com qtype=A, R follows the CNAME 3. C looks up qname=example.com qtype=MX, R follows the CNAME The resolver will first resolve the MX record, and cache that correctly, passing the result back to the client. The second query though will result in a CNAME, which will likely invalidate the cached MX record, and the resolver will then follow the CNAME and chase that. The third query may now also follow the CNAME, even though there may not be an MX record at the CNAME target (foo.example.org). Any non-MX query behind resolver R effectively poisons R's cache, and the MX becomes unreachable. If R gets no queries other than MX queries, or if the MX and CNAME target answers are cacheable for identical periods of time, then it can sometimes work - but it's a tenuous and non-deterministic stroke of luck. If there's even one lookup behind R - from any of its clients for a non-MX, things break again. Some mail servers do perform an A lookup before an MX lookup (which is valid RFC822) and so things never work for those mail servers, as they always poison the cache, but that correlation isn't really the cause of the problem. The configuration is unreliable even in the best of circumstances. Full disclosure: I work on Route 53.
- wut42 13y agoAlso it seems that some DNS resolvers with DNSSEC enabled will not resolve APEX on CNAME (returning a SERVFAIL). I've disabled DNSSEC on my home resolver (unbound) because of this (damn heroku).
- blueskin_ 13y ago>I started to look for solutions and was expecting to have to start using my domain with the "www" until I stumbled across this AWS Blog on how to do exactly what I was wanted. The only "problem" was I would have to use Route 53 instead of CloudFlare for it to work. This is why rewriting exists.