Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have different set of CNAMEs pointing to different subdomains. These subdomains (, are pointing to different IPs on different machines.

# Server A pointing to pointing to
.. pointing to

# Server B pointing to pointing to
.. pointing to

Currently, we have to add individual CNAME entries (eg. a1... aN) against a single subdomain ( We repeat the above process for every new server which is actually another subdomain (e.g. Is there a way we can specify a range of CNAMEs (e.g. [a1..a25] point to 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
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:


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

ServerAlias a*

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

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

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 /, and then use the * wildcard

share|improve this answer

Your Answer


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.