Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have different set of CNAMEs pointing to different subdomains. These subdomains (a.domain.com, b.domain.com) are pointing to different IPs on different machines.

# Server A
a1.domain.com pointing to a.domain.com
a2.domain.com pointing to a.domain.com
..
aN.domain.com pointing to a.domain.com

# Server B
b1.domain.com pointing to b.domain.com
b2.domain.com pointing to b.domain.com
..
bN.domain.com pointing to b.domain.com

Currently, we have to add individual CNAME entries (eg. a1... aN) against a single subdomain (a.dominan.com). We repeat the above process for every new server which is actually another subdomain (e.g. c.domain.com). Is there a way we can specify a range of CNAMEs (e.g. [a1..a25].domain.com point to a.domain.com) instead of adding separate CNAME etnries?

Is there any possibility to handle this at DNS or webserver (apache or Nginx) level?

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

Yes, it is possible to handle this in both DNS (if you are using BIND) and Apache (partially)/nginx (fully).

BIND supports the $GENERATE keyword and you can do the following:

$GENERATE 1-10 a$.domain.com CNAME a.domain.com

In Apache you can only use a wildcard for ServerAlias, not a regular expression:

ServerAlias a*.domain.com

In nginx you can use a regular expression for server_name:

server_name ~^a[1-10]\.domain\.com$;
share|improve this answer
    
Vladimir, thanks for precise and comprehensive answer. I have a starting point now and will look into it further to figure out which servers our needs best. Thanks again. –  Imran Jun 18 '12 at 9:18
add comment

DNS has only one wildcard: *

There's nothing wrong with listing all of those entries in a zone file.

I'm pretty sure Apache can't do ranges like that in ServerAlias directives but it wouldn't surprise me if nginx could handle regexes in its server directive.

You could generate your web server config or your DNS config by using seq 1 25 or a tool such as puppet if typing them all out by hand is too onerous.

You could also do this at the application level if all these different domains should be running the same app. (That's how the company I work for does it.)

share|improve this answer
    
Thanks for your response and suggestions. –  Imran Jun 18 '12 at 9:16
add comment

A BIND specific answer has already been given; but in case anyone has the same problem with a different server and only has access to the basics, my thought would be to change the addresses to X.a.domain.com / X.b.domain.com, and then use the * wildcard

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.