Is it possible to have regular-expression CNAME record in DNS?

Solution 1:

DNS doesn't. But the most popular bind9 nameserver daemon supports this kind of syntax in its zone files:

$GENERATE 1-99 www$ CNAME www$.other-domain.com.

Beware that this is incompatible with other DNS server software.

Solution 2:

The DNS protocol does not support regular expressions. This said, there is no reason why a name server should not have the capability to evaluate regular expressions internally and serve standard DNS answers.

It won't work with the standard zone format as defined in RFC 1035 section 5 and RFC 1034 section 3.6.1 and I'm not aware of any name server actually implementing support for regular expressions, but basically it is possible.

Solution 3:

Although regex handling could be written into a DNS server it would be a bad idea to do so.

Any DNS server modified to handle regex expansion is going to have trouble co-existing with the rest of the world. Zone transfers to "standard" servers would either be incomplete, incorrect or absolutely massive, as each permutation would have to be sent as a separate record. Depending on the regex that could result in an almost infinite number of possible records, which is clearly impractical because the transfer may never complete, leaving systems out of sync.

Of course if transfers were only ever to happen between modified servers this might be OK but the universe has a tendency to destroy such simplicity.