Ready for a quick setup of DNS server bind on OS X? Here we go! You need admin access rights to do this, so to make it easy, I suggest you do all the file editing in the terminal with vi or pico. This guide is best for a one domain, one IP setup, although it is true for any configuration with some changes. Use this guide if you know nothing about DNS and want to set things up quick or if you know what you’re doing and need to know which files OS X is using. ….not valid for Leopard Server!
- Open /etc/named.conf in your favorite editor (or sudo vi /etc/named.conf)
Add a foward zone for each do main, like this. The zone is the name of the domain you want to host and the file is what file will have to domain’s configuration in it. You need one for each domain you’re hosting.
Add a reverse zone for each IP subnet which will be used for the domains.Set the zone to the first three digit groups of the subnet, backwards. So, 192.168.0.x will be written 0.168.192. I know, it’s a little weird. In both the foward and reverse files, what file name you choose is really arbitrary. You just have to be consistent. The files themselves will be in /var/named.
- Save the changes to named.conf and close the file. The file should look something like this: (if you can’t see the whole thing, copy and paste it into an editor)
//
// Include keys file
//
include "/etc/rndc.key";
// Declares control channels to be used by the rndc utility.
//
// It is recommended that 127.0.0.1 be the only address used.
// This also allows non-privileged users on the local host to manage
// your name server.
//
// Default controls
//
controls {
inet 127.0.0.1 port 54 allow {any;}
keys { "rndc-key"; };
};
options {
directory "/var/named";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
};
//
// a caching only nameserver config
//
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
zone "kiwimod.com" IN {
type master;
file "named.kiwimod.com";
};
zone "129.234.60.in-addr.arpa" IN {
type master;
file "named.129.234.60";
allow-update { none; };
};
logging {
category default {
_default_log;
};
channel _default_log {
file "/Library/Logs/named.log";
severity info;
print-time yes;
};
};
- Save the changes to named.conf and close the file.
- Create the foward zone file we specified earlier (named.kiwimod.com) in /var/named. This directory will also contain named.local and named.ca. Just leave these files alone. They are fine as they are.
- Open the file in an editor. (Again, sudo is very useful for this.) Type in this, changing the names to fit your site:
; DNS for KiwiMod.com
$TTL 86400 ; 1 day
kiwimod.com. IN SOA ns.kiwimod.com. admin.kiwimod.com. (
2003040101 ; Serial
10800 ; Refresh after 3 hours
3600 ; Retry after 1 hour
604800 ; Expire after 1 week
86400 ) ; Minimum TTL of 1 day
; name servers
@ IN NS ns.kiwimod.com.
@ IN MX 10 mail.kiwimod.com.
; host to address mappings
@ IN A 60.234.129.2
mail IN A 60.234.129.2
ns IN A 60.234.129.2
; aliases
www IN CNAME mail
amy IN CNAME mail
- Save and close the file.
- Create the reverse zone file (named.129.234.60 or whatever you called it) in /var/named. Edit the file to read:
; Reverse lookup for 60.234.129.2
$TTL 86400 ; 1 day
129.234.60.in-addr.arpa IN SOA ns.kiwimod.com. root.kiwimod.com. (
2003040101 ; Serial
10800 ; Refresh after 3 hours
3600 ; Retry after 1 hour
604800 ; Expire after 1 week
86400 ) ; Minimum TTL of 1 day
; name servers
129.234.60.in-addr.arpa IN NS ns.kiwimod.com.
; address to host mappings
2 IN PTR kiwimod.com.
2 IN PTR ns.kiwimod.com.
2 IN PTR mail.kiwimod.com.
- Just change the IP and domain bits to be your settings. The digit 2 in address to host mappings is the last number of the IP address. In this example, only one IP is being used for the domain, but using more than one works pretty much the same way, you just need additional reverse zone files and reverse lookup settings in named.conf.
That’s it. All you have to do now is start up named and see if it worked.
In the terminal, type:
sudo named -c /etc/named.conf
to start up the nameserver. To see if the name is resolving, try digging it:
dig kiwimod.com
or
dig 192.168.your.IP
Use your own IP of course, the IP of the server that is. You should get back some information about the server, like what IP the nameserver has. If not, then something has gone horribly wrong!