Mac Wildcard DNS & apache subdomain vhosts

Instructions for when I need to do this again and get frustrated with the python DNS server.

First, we setup our local DNS server.

sudo rndc-confgen -a -c /etc/rndc.key 
sudo vi /var/named/dev.local

Populate contents of dev.local with:

dev.local. 7200    IN       SOA     dev.local. (
                     2008031801 ;    Serial
                     15      ; Refresh every 15 minutes
                     3600    ; Retry every hour
                     3000000 ; Expire after a month+
                     86400 ) ; Minimum ttl of 1 day 
dev.local. IN      NS      dev.local. 
dev.local. IN      MX      10 dev.local. 
dev.local. IN      A       {DESTINATION_IP} 
*.dev.local.    IN      A       {DESTINATION_IP}

No, {DESTINATION_IP} is not a variable. Replace it with the IP of your apache server. if local.

sudo vi /etc/named.conf


zone "dev.local" IN {
         type master;
         file "dev.local";

If there are errors presented by either of these commands, follow the logical instructions on resolving the errors

sudo named-checkconf /etc/named.conf 
sudo named-checkzone dev.local /var/named/dev.local

Add the org.isc.named daemon to startup and flush your dns cache

sudo launchctl load -w /System/Library/LaunchDaemons/org.isc.named.plist 
sudo dscacheutil -flushcache

Add to the DNS entries in the System Preferences Advanced adapter config (any adapters used)

Test the setup works:


The ->>HEADER<<- line should read:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9635

If there is an error, it’ll read something like:

;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 21136

When troubleshooting what the error might be, be sure to bounce the org.isc.named daemon if editing the various configuration files.

sudo launchctl stop org.isc.named 
sudo launchctl unload -w /System/Library/LaunchDaemons/org.isc.named.plist 
sudo launchctl load -w /System/Library/LaunchDaemons/org.isc.named.plist 
sudo launchctl start org.isc.named

Once that is completed, on the apache server (ubuntu for me)

sudo a2enmod vhost_alias

Next, modify your vhost

<VirtualHost *:80>
    ServerName dev.local
    ServerAlias *.dev.local
    ServerAdmin webmaster@localhost
    VirtualDocumentRoot /path/to/site/directories/%1
    <Directory /path/to/site/directories>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all