Sep 27

Development Environment Tip: setting up dns wildcards

Sun, 09/27/2009 - 11:02 — peter

The Problem

So you got a new customer site to do. You want a new host name for the development site (like customername.yourdomain.tld), so you modify your local hosts file OR, if you have any scalability in your setup, you go and add a new CNAME record to your name server setup and all is good, right?

Well, by client #5 this process begins to become annoying and by client #10 you are looking for an alternative method of managing these names.

The Solution

Enter wildcard dns! For the sake of simplicity, I will assume you are running a bind9 dns server on your own development box - probably unnecessary in a real environment, but still the same principles apply to pretty much any name server out there...

So your dns zone file looks something like this:

$ttl 3600
@                       IN      SOA     devbox.yourdomain.tld. peter.yourdomain.tld. (
                        2005051901      ; serial
                        3h              ; refresh interval
                        1h              ; retry interval
                        1w              ; expire
                        2h    )         ; minimum ttl
                        IN      NS      devbox.yourdomain.tld.
                        IN      MX 50   devbox.yourdomain.tld.
@                       IN      A       10.0.0.1
customer1               IN      CNAME   @
customer2               IN      CNAME   @
customer3               IN      CNAME   @
customer4               IN      CNAME   @
customer5               IN      CNAME   @

That setup lets you hit all 5 customers on your development box. Now let's make that setup more dynamic! Let's change those 5 last lines to a wildcard, to something like this:

$ttl 3600
@                       IN      SOA     devbox.yourdomain.tld. peter.yourdomain.tld. (
                        2005051902      ; serial
                        3h              ; refresh interval
                        1h              ; retry interval
                        1w              ; expire
                        2h    )         ; minimum ttl
                        IN      NS      devbox.yourdomain.tld.
                        IN      MX 50   devbox.yourdomain.tld.
@                       IN      A       10.0.0.1
*                       IN      CNAME   @

That is it. Don't forgot to change that serial number on the zone file and reload or restart your bind name server. Now any name on the .devbox.yourdomain.tld will respond to the IP of your development box.

Easy Peasy!
-PCP