Today we are going to set up our virtual machine so that it mimics the awesome work that Elliott did on our dev server, and adjust things so that it’s a little better suited for local development, to accomplish this we’ll get a DNS server working on our host machine. Setting up apache on your Virtual Machine following that article gets us half way there. Any new sub-directory we setup in our virtual machine users home directory (/home/[username]/www/[folder]) our virtual machine becomes a new site (mirzu.test.local), however in our laptop we still need to add new entries to the /etc/hosts file for each new host. This is because OSX doesn’t allow wildcard entries like *.local which would handle all requests to .local. To fix this issue we’ll need to get our own DNS Server running. A process that sounds scary but really isn’t.

1. Edit /etc/named.conf

On your Laptop edit /etc/named.conf and add the following block, called a “zone”, to the end of the file:

zone "local" IN {
type master;
file "local.zone";
allow-update { none; };
};

2. Create the Zone File

In the code above we create a pointer to a zone file called local.zone Bind will look in the folder /var/named/ so we add the file /var/named/local.zone.

Here is mine:


$TTL 60
$ORIGIN local.
@ 1D IN SOA localhost. root.localhost. (
45 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum

*.local. 60 IN A 172.16.39.144

The ip address 172.16.39.144 is the IP of my virtual machine.

Checking the files

We can use some of Bind’s utilities to test the files.

$ sudo named-checkconf /etc/named.conf
$ sudo named-checkzone local /var/named/local.zone

The first command should return nothing and the second’s response should end with “OK”

Setup & Start Bind

This is where I had some trouble with some of the other examples on the web, but hopefully the below steps should be fairly bullet proof.

Setup the keys bind needs


$ rndc-confgen > /etc/rndc.conf
$ head -n 6 /etc/rndc.conf > /etc/rndc.key

3. Start up the Deamon

OSX’s Launch Deamon command has a handy option that’ll start the Deamon and add it to the Deamons that are included in startup.

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

Now lets make sure it’s running.

$ ps aux | grep named
mirzu 1920 0.2 0.0 2432768 620 s003 R+ 1:22PM 0:00.00 grep --color=auto named
root 992 0.0 0.1 2440496 8736 ?? Ss 11:07AM 0:01.77 /usr/sbin/named -f

If you have any issues at this point start up the Console.app and look at the output. You should see some entries with the word Bind in them.

4. Verify that everything is working

You can use the awesome utility dig included with Bind. Or just try pinging the domains you expect to work.

Using Dig

We are going to ask localhost to resolve our test domain to insure things are working.

$ dig @localhost test.local

; <<>> DiG 9.8.1-P1 <<>> @localhost test.local
; (3 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59471
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;test.local. IN A

;; ANSWER SECTION:
test.local. 60 IN A 172.16.39.144

;; AUTHORITY SECTION:
local. 86400 IN NS localhost.

;; ADDITIONAL SECTION:
localhost. 86400 IN A 127.0.0.1

;; Query time: 10 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Aug 29 13:28:57 2012
;; MSG SIZE rcvd: 83

If that output seams like gibberish to you you can use the simpler ping command.

Using Ping


$ ping test.local

PING test.local (172.16.39.144): 56 data bytes
64 bytes from 172.16.39.144: icmp_seq=0 ttl=64 time=0.329 ms
64 bytes from 172.16.39.144: icmp_seq=1 ttl=64 time=0.295 ms

--- test.local ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.295/0.312/0.329/0.017 ms

Again if you have issues Console.app is your friend.

5. Adding your your local DNS Server to your list of DNS servers