First, there is no redirection in DNS. This is a term defined and used in the HTTP world, it doesn't exist in the DNS. At best, you can speak about aliases in case of CNAME.
The resolution algorithm in the DNS is outlined in https://datatracker.ietf.org/doc/html/rfc1034#section-4.3.2
CNAME does not behave like a "sub domain wildcard" as you seem to think of.
Once a CNAME
exists, nothing can exist below. So a resolver attempting the "sub" name will get an authoritative answer saying the name does not exist and should stop there. If it climbs up, or down from the root, it should find the CNAME
itself, and then continue searching there (but not with a wildcard sense). You may want to look at the DNAME
record that provides the semantic you seem to want to have (look at the Wikipedia page on CNAME
at https://en.wikipedia.org/wiki/CNAME_record and see the relevant line in the DNAME
section: "However, a lookup for xyzzy.foo.example.com will be DNAME mapped and return the A record for xyzzy.bar.example.com, which is 192.0.2.24; if the DNAME record had been a CNAME record, this request would have returned name not found.").
Or you create *.blog.example.com
as a wildcard, which can be a CNAME
or any other things. Do note that in history, CNAME
and wildcards did create lots of confusion and errors, so not something to use when you just start with the DNS (easy to provision each name precisely in the zone file)
You can try for yourself, right now:
$ dig www.icann.org CNAME +noall +ans
www.icann.org. 57m53s IN CNAME www.vip.icann.org.
So we have this CNAME. If we want to try your sub name case:
$ dig test.www.icann.org CNAME +noall +auth
icann.org. 1m57s IN SOA sns.dns.icann.org. noc.dns.icann.org. (
2022051953 ; serial
10800 ; refresh (3 hours)
3600 ; retry (1 hour)
1209600 ; expire (2 weeks)
3600 ; minimum (1 hour)
)
or (this does an A by default)
$ dig test.www.icann.org +noall +auth
icann.org. 2m IN SOA sns.dns.icann.org. noc.dns.icann.org. (
2022051953 ; serial
10800 ; refresh (3 hours)
3600 ; retry (1 hour)
1209600 ; expire (2 weeks)
3600 ; minimum (1 hour)
)
If you look at the status you will see NXDOMAIN
(domain does not exist) for those cases.