Technology

Install ISC DHCP on Mac OS X Server

First off, I should say that I am a big fan of the DHCP server (bootpd) bundled with Mac OS X Server. It is a great solution for small networks (eg. home or small office networks), as it is rock solid, and management via the Server Admin GUI makes configuration and management easy. However, having run the DHCP server bundled with Mac OS X Server on a 2000 node network for two years, management started getting…complicated. To make a long story short, while the Server Admin GUI interface is great for small networks with one or two subnets, once you start pushing out many subnets with large numbers of statically assigned IP addresses, that interface becomes a monster to maintain.

This is where ISC’s DHCP software comes in. Managing ISC’s DHCP server comes down to management of two or three text files, depending on your configuration, that can easily be manipulated using a text editor…not a GUI interface like Server Admin. ISC’s DHCP server is every bit as rock solid as the DHCP server bundled with Mac OS X Server, and won’t give those who manage large networks a headache when it comes time to manage subnets and static IP assignments.

 

Download & Install the ISC DHCP software

First, you will want to have Mac OS X Server installed…this how-to should work for v10.4, v10.5 and v10.6…with Xcode installed. Update: If you are running a version of OS X Server newer than that, I cannot vouch for whether or not this will work, so you are on your own.

Once you have Mac OS X Server and Xcode installed, you will want to download the ISC DHCP software. There are various methods to download, curl or visiting the ISC DHCP software webpage and downloading the latest release version are two of the easiest. As of this writing, the latest release version is DHCP 4.2.1-P1. For this how-to, we will use curl, so open Terminal (if you’re asking what Terminal is, just stop right now…this is not something you want to be doing) and type the following:

curl -O http://ftp.isc.org/isc/dhcp/dhcp-4.2.1-P1.tar.gz

Once the file download has completed, uncompress it with gnutar

gnutar -xzvf dhcp-4.2.1-P1.tar.gz

With the file unpacked, navigate into the uncompressed folder…

cd dhcp-4.2.1-P1

Once inside the uncompressed folder, run the following three commands to build and install the ISC DHCP software…

./configure
make
sudo make install

Congratulations, you have installed the ISC DHCP software on Mac OS X Server. The dhcpd daemon will be installed in either /usr/sbin/or /usr/local/sbin/ (it appears to depend on which version of Mac OS X Server you are running…for Mac OS X Server v10.6, dhcpd is installed in /user/local/sbin/dhcpd, earlier versions of Mac OS X Server install dhcpd in /usr/sbin/).

 

Configuring the ISC DHCP Server

Now the real fun of configuring dhcpd can begin. First, you will need to configure an /etc/dhcpd.conf file, with DHCP 4.2.1-P1, you will find a sample dhcpd.conf file in /usr/local/etc/. Either copy the /usr/local/etc/dhcpd.conf file or create a new dhcpd.conf file in /etc/.

To copy the /usr/local/etc/dhcpd.conf file to /etc/dhcpd.conf, run the following command in Terminal…

sudo cp /usr/local/etc/dhcpd.conf /etc/dhcpd.conf

To create a new dhcpd.conf file in /etc/, run the following command…

sudo touch /etc/dhcpd.conf

Below is a commented example of a dhcpd.conf file. There are many, many settings to choose from, so I cannot possibly cover them all here. I would highly recommend reading through the dhcpd man pages, but these are the basics…

# /etc/dhcpd.conf
#
# Necessary to actually be a DHCP server
authoritative;
ddns-update-style none;
# Default DHCP configuration info
default-lease-time 43200;
max-lease-time 86400;
server-name "dhcpserver.domain.com";
# DNS servers that your clients will use
option domain-name-servers 10.0.1.1, 10.0.1.2;
# Search domain that your clients will use
option domain-name "domain.com";
# DHCP Static Assignments configuration file
include "/etc/dhcpd/master.conf";
#
################## [ SUBNETS ] ##################
# Subnet 1 - A set of IP address that are manually or statically assigned
subnet 10.0.1.0 netmask 255.255.255.0 {
option broadcast-address 10.0.1.255;
option subnet-mask 255.255.255.0;
option routers 10.0.1.254;
}
# Subnet 2 - A set of IP addresses are dynamically or statically assigned
subnet 10.0.2.0 netmask 255.255.254.0 {
option broadcast-address 10.0.3.255;
option subnet-mask 255.255.254.0;
option routers 10.0.3.254;
pool { range 10.0.2.1 10.0.3.254; }
}

The subnet of your DHCP server’s IP address MUST be included in the dhcpd.conf file, otherwise dhcpd is very unhappy and will not start.

Note the following lines in the dhcpd.conf file…

 # DHCP Static Assignments configuration file
 include "/etc/dhcpd/master.conf";

That allows you to keep your static IP assignments in a file separate from the primary configuration file. This is quite nice as you are not editing the primary configuration file every time you want to add/change/remove a static IP assignment. Here is a brief sample of the master.conf file for dhcpd static IP assignments…

# Master Configuration file for DHCP - contains all static assignments
# /etc/dhcpd/master.conf
#
# STATIC IP ASSIGNMENTS
############################################
## SUBNET 1 - 10.0.1.0/24
############################################
host device1 { hardware ethernet 00:30:65:aa:bb:cc; fixed-address 10.0.1.1; }
host device2 { hardware ethernet 00:30:65:bb:cc:dd; fixed-address 10.0.1.2; }
#
############################################
## SUBNET 2 - 10.0.2.0/23
############################################
host device3 { hardware ethernet 00:30:65:cc:dd:ee; fixed-address 10.0.2.1; }
host device4 { hardware ethernet 00:30:65:dd:ee:ff; fixed-address 10.0.2.25; }
host device5 { hardware ethernet 00:30:65:ee:ff:gg; fixed-address 10.0.3.100; }

Once you have your dhcpd.conf and master.conf file setup, you will need to create the lease file, otherwise dhcpd will not run. In Terminal, run the following command…

sudo touch /var/db/dhcpd.leases

 

Start dhcpd and Test

You can now start up dhcpd and being testing your configuration…

sudo /usr/local/sbin/dhcpd -q -f

…look for any messages in /var/log/system.log that may indicate problems. The system.log file is typically verbose enough that you can quite easily figure out what is going wrong.

You can now grab a client machine (Mac OS X, iOS, Windows, whatever) and test to make sure you are getting an IP address from your newly configured DHCP server. Check System Preferences > Network to verify that you are in fact getting an IP address, then you can run the following command in Terminal to verify what DHCP server that IP address is coming…

ipconfig getpacket en0

In the output, you should see an sname field that will tell you the name of the DHCP server your IP address is originating from. If it is showing the name of your newly configured DHCP server, you are golden…dhcpd is properly configured.

 

Keep dhcpd Running with launchd

Launchd will automate the launching of dhcpd, so you do not have to manually restart it after rebooting your server, or after a power outage, etc. It’s quite simple to implement. Below is an example launchd configuration file for the ISC DHCP server.

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
 <!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
 <plist version=\"1.0\">
 <dict>
 <key>Label</key>
 <string>org.isc.dhcpd</string>
 <key>OnDemand</key>
 <false/>
 <key>ProgramArguments</key>
 <array>
 <string>/usr/local/sbin/dhcpd</string>
 <string>-q</string>
 <string>-f</string>
 </array>
 <key>RunAtLoad</key>
 <true/>
 <key>ServiceDescription</key>
 <string>ISC DHCP Server</string>
 </dict>
 </plist>

Put this into a file named org.isc.dhcpd.plist inside /Library/LaunchDaemons/, and then load it into launchd using launchctl

sudo launchctl load /Library/LaunchDaemons/org.isc.dhcpd.plist

Test to see if the configuration file loaded into launchd

sudo launchctl load org.isc.dhcpd

…and/or test to see if dhcpd is running…

ps -ax |grep dhcpd

So that’s it, ISC’s DHCP software is now installed and running on your Mac OS X Server. At some point in the future, I will post a how-to on setting up a failover ISC DHCP server…in the rare case that your ISC DHCP server stop working.