This is really just an approach for locally testing DNS changes, which can easily be done with a HOSTS file if the change involves an IP address, but gets a bit trickier when things like CNAMEs are involved. This is only meant to test locally off a single machine.
-
Install bind using homebrew
brew install bind
-
Follow the installation steps to start up bind
To have launchd start bind at startup: sudo cp -fv /usr/local/opt/bind/*.plist /Library/LaunchDaemons Then to load bind now: sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.bind.plist
-
Create a new zone file. This can technically live wherever, but it's probably a good idea to keep it close to the
name.conf
which is bind's main config file. Homebrew installs it here:/usr/local/etc/
. It's smart to use the name of the domain and name it something likedb.example.org
.Enter something like the following:
; ; BIND data file for example.org ; $TTL 4h @ IN SOA ns1.example.org. root.example.org. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns1.example.org. @ IN A 123.12.34.57 www IN A 123.12.34.57 ns1 IN A 127.0.0.1
There's a great breakdown of what this file means here. The main thing to note is that ns1 or your name server should point to your machine.
-
Update the
named.conf
file to point to your new zone.zone "example.org" { type master; file "/usr/local/etc/db.example.org"; };
-
Verify that there are no errors in both files using the following commands.
named-checkconf /usr/local/etc/named.conf named-checkzone db.modern.ie /usr/local/etc/db.modern.ie
If everything is right, the first command should output nothing. The second command should print OK on the last line.
-
Set your machine's DNS to point to your machine as a nameserver.
Example: Changing DNS server settings on Mac OS 10.5
- From the Apple menu, click System Preferences, then click Network.
- Select the connection for which you want to configure DNS. For example: To change the settings for an Ethernet connection, select Built-In Ethernet, and click Advanced. To change the settings for a wireless connection, select Airport, and click Advanced.
- Select the DNS tab.
- Click + to replace any listed addresses with, or add, the address 127.0.0.1.
- Click Apply and OK.
-
Flush your DNS cache with the following command.
dscacheutil -flushcache
-
Restart bind with the following commands.
sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.bind.plist sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.bind.plist
-
Validate that your domain is now using your local DNS.
nslookup www.example.org localhost Server: localhost
I also added a resolver that pointed to 127.0.0.1, but I'm not sure it is actually needed.
Create configuration so that the wilcard is still accesible when you are not connected to a network.
mkdir /etc/resolver vim /etc/resolver/org
Add the following:
nameserver 127.0.0.1
This should route all .org domains through your local DNS server.