1

Is it possible to do something like this? Or any equivalent? in a DNS server.

([0-9]{2})\.example\.com\.  IN  CNAME   www$1.example.net.
4
  • 1
    Definitely a server fault I'd say Apr 19, 2010 at 2:42
  • I googled and found NAPTR record, how does it work?
    – Van Nguyen
    Apr 19, 2010 at 2:46
  • 6
    Your DNS server can reply with whatever it wants for any query. A CNAME record isn't the solution, but a regex-based DNS server is something you could find or write.
    – jrockway
    Apr 19, 2010 at 2:46
  • I don't think you can use NAPTR records, they are reverse DNS records. Apr 19, 2010 at 10:28

7 Answers 7

8

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.

0
4

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.

4

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.

2
  • Then how does wildcard works then? Isn't that "infinite" number of possibilities as well?
    – Van Nguyen
    Apr 19, 2010 at 11:20
  • 1
    @Kaizoku The * wildcard is a standard DNS feature, and during AXFRs (zone transfers) it is transferred just like that: *, because the receiving server will know what it means. But if you implement DNS regexps in the master server but not in the slave, the situation described by John occurs. Apr 19, 2010 at 11:31
2

No. But you can have a wildcard:

*.mydomain.com

which won't quite do what you want, but maybe you can do some server-side validation to ensure that the hostname is valid? Won't help with re-writing to a different A record though...

2
  • But that is many-to-one I think. Does wildcard work on the other domain as well?
    – Van Nguyen
    Apr 19, 2010 at 3:20
  • Correct, it is many:one - and no, there's no wildcard on the other domain. DNS is not designed for this sort of functionality, but if you wanted to modify the DNS daemon (say bind) I'm sure you could add this functionality in. Apr 19, 2010 at 3:28
2

You can't do this with standard DNS software.

It is possible if you use a custom DNS server which recognises that particular pattern and then dynamically synthesises the correct response. It would actually be trivial for example using my evldns server framework. If you know 'C' it should take less than an hour to implement.

Note however that all authoritative DNS servers for the domain would need to have this feature. Whilst a wildcard record can be happily transferred from primary to secondary servers using AXFR, that only works because it's built into the DNS protocol.

1

No regex, just wildcard domain names, e.g. *.mydomain.net - (RFC 4592, especially section 2)

1

As jrockway suggested, if you can afford to roll your own nameserver, you have full control over the replies you give. In that case, you could reply with the CNAME record you want, based on the query. I don't know how much DNS traffic you expect to have, how mission critical your web site is, but you could try a DNS server implemented in Perl, using the Net::DNS::Nameserver module.

Alternatively, since your regex is just a shortcut for 100 DNS resource records, you could just run BIND, and have a script generate the zone file you want.

Or, just use your registrar's tools to create the 100 CNAME records.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .