Thursday, 24 October 2013

Dynamic vhosts using a central DNS server

I was inspired by Evans & Robs blogpost about dynamic vhosts using nginx/apache and we used this a fair amount at our office but it's not really useful if you want to quickly share your work with colleagues.

Links to their blogposts
http://blog.evan.pro/how-to-set-up-dynamic-virtual-hosts-for-web-development (Nginx)
http://akrabat.com/computing/automatic-apache-vhosts/ (Apache)

I set about setting up a centralised DNS server that i could use fake TLD's to point to each persons computer. If i would have used dnsmasq instead it would have been a lot easier.... But unluckily i had a fat configuration of bind that i didn't want to migrate to dnsmasq.

Doing this with bind9 step 1

Edit /etc/bind/named.conf.local and add a section zone for each colleague
zone "antoine" {
        type master;
        file "/etc/bind/db.antoine";
};

zone "jonas" {
        type master;
        file "/etc/bind/db.jonas";
};


Save and create a new file for each zone that you have created
; BIND db file for antoine

$TTL 86400

@       IN      SOA     |NAMESERVER DOMAIN|.      |EMAIL DOT DOMAIN|. (
                        2013102401      ; serial number YYMMDDNN
                        28800           ; Refresh
                        7200            ; Retry
                        864000          ; Expire
                        86400           ; Min TTL
                        )

                NS      |NAMESERVER DOMAIN|.

$ORIGIN antoine.

*       3600    A       192.168.0.7


So for us that would be
; BIND db file for antoine

$TTL 86400

@       IN      SOA     router.pmg.se.      spam.pmg.se. (
                        2013102401      ; serial number YYMMDDNN
                        28800           ; Refresh
                        7200            ; Retry
                        864000          ; Expire
                        86400           ; Min TTL
                        )

                NS      router.pmg.se.

$ORIGIN antoine.

*       3600    A       192.168.0.7

I will be frank when i say i have no idea why i have to specify an email in the zone SOA declaration or why it's in that format. I might even have done something terrible wrong.... but it works and it allows me to visit my collegues projects without having to edit my /etc/hosts

No comments:

Post a Comment