Setting up a Name Server using "named"



Important note: This article was written a while ago for Mac OS X Server 1.x (using Bind 4.x), not the current version of Mac OS X or Mac OS X Server 2 (which use Bind 8.x).
(To check your version of Bind, type "named -v" at the command line.)

Abstract: On OSX Server, you already have the program you need to start running your computer as a name server, "named," which is a version of Bind. The only pain is that you have to set up a few files first to get things running, and you have to maintain those files as your set-up grows. This all could be handled by a nice GUI, but currently isn't, so this is a quick guide to get you going until then. This is not meant to be authoritative, but rather a convenient quick-start guide. Feel free to send me feedback.


Index:

  1. Non-OSXS Preliminaries
  2. Setting up the "named" files
    1. named.boot
    2. named.local
    3. named.hosts
    4. named.rev
    5. resolv.conf
  3. Working with Apache
  4. Adding new Domains / Sub-domains
Additional Resources:
  1. Named Man Pages (local copy)
  2. O'Reilly's DNS and BIND
  3. Bind Operations Guide
  4. Steve Limkemann's DNS Advice
  5. Olaf Kirch's Running Named
  6. Setting up DNS


next section
back up top


Non-OSXS Preliminaries:

Of course, to get this whole show off the ground, you have to have a domain name registered, at least one static IP address, and have your machine registered as a name server with Network Solutions. To get yourself registered as a domain name server, head over to Create a Name Server Host. It's quick and easy, and more importantly, free. You have to pick a name for your name server, and you may want to name it something like "ns.yourdomain.com" or somesuch. They walk you through the procedure, and I believe you have to bounce a few emails back to them and so forth. Can be done while you're setting up your name server.

Now, you then have to tell Network Solutions that your web domain (and I'm assuming that you have one, or that someone out there who is planning on using your name server has one) has your machine listed as the primary name server. So head over to make any changes to your current web domain and get your name server info updated.

But what about the *secondary* name server? Well, if you only have one machine that going to be doing the name serving, you'll have to find someone else's machine (which runs a name server) to agree to be the secondary name server for your web domain. That means supplying them with info about your domain and probably agreeing to pay them some small monthly fee to handle the traffic should your site go down for whatever reason. Often, your ISP may agree to slightly hike up your monthly bill in exchange for being the secondary name server. Or, you may have a friend who has a name server - and this is probably the most cost-effective route - and you can each agree to be each other's secondary name server. (You may want to make sure you each get about the same level of net traffic, so that one of you doesn't get unduly overloaded if the other goes down.) If you have more static IP address and another machine that can function as a secondary name server, you may want to register that as a name server and set it up as well. Of course, if both machines go down, then all outside requests for your domain name will come up with no info at all, so make a guess as to what's best for your situation. (I have my ISP secondarily name serve me.)


next section
last section
back up top


Setting up the "named" files:

There are five files which you need to create in the /etc directory:

named.boot, named.local, named.hosts, named.rev and resolv.conf.

(Actually, you can put these files other places, and you could even keep them in /local/ directories for people running multiple named processes, but I'm just going to set it up the way it is on my machine, assuming that you, the admin, are in charge of all this.) Their set up is a bit odd, but formulaic at least. I'm going to just write them out in text form, so that you can simply copy them and paste them into a text editor, but I'm going to make up a demo web host and ip#. So, let's say the web domain is yourdomain.com at IP# one.two.three.four, and let's say we registered our name server as ns.yourdomain.com.

Once you get all these files in place, you should be all ready to go with one simple command: named & (the "&" runs the process in the background, in case you haven't run across that before). You can also add this to your boot file, if you have need to reboot your machine ever. (I have memories of having to reboot, but they're getting hazy now... ;-) If there's something wrong with what I'm saying below, please let me know.

named.boot

(all the files will be in the /etc directory, which, if you're root, is an alias to /private/etc - a good directory to get familiar with if you aren't already)

;
; boot file for name server /etc/named.boot
;
directory /etc

primary         yourdomain.com                  named.yourdomain.hosts
primary         something_else.com              named.something_else.hosts

primary         0.0.127.in-addr.arpa            named.local
primary         three.two.one.in-addr.arpa      named.rev

forwarders      isp.name.server.one     isp.name.server.two
options         forward-only

; load cache data last
cache           .                               root.cache

  • The directory just tells where to find the named files.

  • The term primary means that you'll be designating that this server is the primary server for the following domains. If you end up being a secondary server for someone's domain, you'll add equivalent secondary lines in there. I didn't add anything about it because it's more complicated and this is meant to be a quick-start, afterall. Check out Secondary Service for info on setting up your name server for secondary serving.

  • The first primary line sets up a link with another file, named.yourdomain.hosts, which will contain all of the subdomain ip# address to yourdomain.com (including the "www" subdomain). The next line is an example of having added another domain for your name server do direct, something_else.com, which has its own file filled with subdomain information. Add as many as you point to your name server.

  • The third line points to the file named.local which will contain some specific info about named's behavior. 127.0.0.1 is the address of the "localhost", your computer's address for itself, also called the "loopback" address. It's always this address, so don't alter that line.

  • The fourth line names a file named.rev which will be dishing out the information related to domains that start ip#s with one.two.three... (note: the line above must be in reverse order, like how it's shown!) It's the point of contact between your local system's domains and subdomains and the internic being able to find them (or so is the story I tell myself).

  • The forwarders and options lines form a pair which tell your server to run in slave mode to your isp's name servers. Since you had to find out what your ISP's name server addresses were when you set up your internet account to begin with, these numbers should be lying around somewhere. If not, I'm sure your ISP will tell you if you give them a call.

    (Is running in slave mode necessary? I'm not really sure, but I know that things don't go quite right for me when I take this part out.)

  • The cache line just sets up a cache file for the named process. More info can be found in the named manual (or by typing "man named").

  • There are lots of other things you can add and change about this file, but this is basically all you need to get it up and running smoothly. Again, check out the Bind manual for more.

named.local

;
;  Loopback information   /etc/named.local
;
@       IN      SOA     ns.yourdomain.com. yourdomain.com. (
                        5       ; Serial Number
                        10800   ; Refresh = 3 hours
                        3600    ; Retry = 1 hour
                        432000  ; Expire = 5 days
                        86400   ; Minimum = 1 day
                        )
        IN      NS      ns.yourdomain.com.
1       IN      PTR     localhost.

    This is much easier, just copy it and plug in your specifics. You also need those extra periods at the end of the server and domain names.

    SOA designates your name server as the "Source Of Authority," NS is your name server's official name, and PTR (stands for?) allows name lookups given the ip number. For more about this stuff, check out The DNS Database Files.

    From what I hear, if other machines are connected and using your name server directly, change the serial number each time you restart named. Solo name servers, don't worry about it.

named.yourdomain.hosts

;
; Name Servers

                IN      NS      ns.yourdomain.com

; lookup address

localhost.      IN      A       127.0.0.1

; novel server

www             IN      A       one.two.three.four
fun             IN      A       one.two.three.four

    Nothing fancy going on here. The last two lines are the fun part. This is where you can start dishing out the subdomains. If you're running everything off a single IP number, then just keep repeating that IP number for each subdomain. The above coding hooks up www.yourdomain.com and fun.yourdomain.com.

    Add all the subdomains you want, but remember to tell apache.config what you did (virtual hosting-wise), and also that you have to restart both named and Apache each time you add a subdomain.

named.rev

;
; /etc/named.rev                Reverse mapping of IP addresses
;                               Origin is three.two.one.in-addr.arpa.
;
@       IN      SOA     ns.yourdomain.com. yourdomain.com. (
                                9               ;serial
                                86400           ;refresh:       daily
                                3600            ;retry:         1 hour
                                3600000         ;expire:        42 days
                                604800          ;minimum:       1 week
                                )
        IN      NS      ns.yourdomain.com.
four    IN      PTR     fun.yourdomain.com

    Here we have a file which gives a way for an IP number to get mapped to the correct domain and subdomain. If you don't have a subdomain, then don't add that last line in there.

    (Note that "four" in the above is the last part of your static IP number. If you had several seperate machines with a unique final IP digit each, you'd match the final digit to each subdomain which they handle.)

resolv.conf

;
; /etc/resolv.conf
;
domain yourdomain.com
domain any_others_you_have.com
;
nameserver one.two.three.four        ; that's me, the local nameserver
nameserver your.isp.nameserver.one   ; your isp's name server #1
nameserver your.isp.nameserver.one   ; your isp's name server #2

    This is the simplest of the files. It just contains two bit of info: what domains you have pointing to your name server, and what nameserver's your computer is hooked up to. I'm not positive if you have to include your ISP's name server's in here, but every example I've seen does so, and who am I to argue with success?

    (Of course, as always, if you know better, let me know.)


next section
last section
back up top


Working it out with Apache:

Getting Apache to go along with all this is not too difficult, but I'll just lay out the basics. If you want to know the ins and outs of this, be sure to go through the great Apache site.

You'll have to add a few lines to the apache.conf file, usually located in the

/Local/Library/WebServer/Configurations/

directory. If you haven't already gotten familiar with looking through this file, check it out, it does a lot of great stuff. It also basically walks you through setting up the main domain name. However, if you're planning on having more than just "www".yourdomain.com, you can cut to the chase by adding in this line as you add subdomains:

    < VirtualHost one.two.three.four>
         ServerName www.yourdomain.com
         DocumentRoot /the_directory_for_this_address/
         CustomLog /Local/Library/WebServer/Logs/www.log combined
    < /VirtualHost>

You can add as many of these as you like, and point them all to their own seperate directory or the same ones. I create a seperate log for each subdomain, but you may prefer one big log for all of them by pointing them all to the same logging file. You can keep your web serving files on any of your drives, even the HFS+ drives (for which I've noticed no noticeable speed hit).


last section
back up top


Adding new Domains / Sub-domains:

Ok, just some quick end notes here, as I'm getting tired...

The files you need to update when you are adding a whole new domain are:

    named.boot, named.rev and resolv.conf
    and create a named.newdomain.hosts file

and the files you need to update when you add on a new subdomain to any already hooked up domain:

    named.rev and named.whicheverdomain.com

When you update those, you need to start the named process and restart it again (named &), and also stop and restart the Apache server (apachectl stop, then apachectl start).