Does the * in a CNAME record take priority over explicit subdomains?

Sudhir Jonathan picture Sudhir Jonathan · Feb 7, 2013 · Viewed 12.3k times · Source

I have a set of subdomains defined on my domain like this:

CNAME sub1.example.com -> sub1.herokuapp.com
CNAME sub2.example.com -> sub2.appspot.com
CNAME www.example.com -> example.herokuapp.com

Now I'd like to add CNAME *.example.com -> example.herokuapp.com to catch folks who put in too many WWWs or type in other missing subdomains. But will the * take priority over the explicitly defined subdomains or will the subdomains continue to work as expected?

I'm using Route53 if it makes a difference.

Answer

Anew picture Anew · Feb 7, 2013

Wildcards will only match records that aren't otherwise defined in the zone.

See RFC 1912, it mentions MX records here but the same applies to CNAMEs:

2.7 Wildcard records

Wildcard MXs are useful mostly for non IP-connected sites.  A common
mistake is thinking that a wildcard MX for a zone will apply to all
hosts in the zone.  A wildcard MX will apply only to names in the
zone which aren't listed in the DNS at all.  e.g.,

       podunk.xx.      IN      NS      ns1
                       IN      NS      ns2
       mary            IN      A       1.2.3.4
       *.podunk.xx.    IN      MX      5 sue

Mail for mary.podunk.xx will be sent to itself for delivery.  Only
mail for jane.podunk.xx or any hosts you don't see above will be sent
to the MX.  For most Internet sites, wildcard MX records are not
useful.  You need to put explicit MX records on every host.