Running Mac OS X's built-in DHCP server
It turns out that Mac OS X comes with a DHCP server built-in. There don't seem to be any good and simple instructions out there on how to use it. Or at least, there weren't any.... until now!
The server is called bootpd and does both DHCP and BOOTP. These instructions just describe using it for DHCP, however.
To start, you need to create a configuration file for the server. The file should be stored in /etc/bootpd.plist
. Here's a sample configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bootp_enabled</key>
<false/>
<key>detect_other_dhcp_server</key>
<integer>1</integer>
<key>dhcp_enabled</key>
<array>
<string>en0</string>
</array>
<key>reply_threshold_seconds</key>
<integer>0</integer>
<key>Subnets</key>
<array>
<dict>
<key>allocate</key>
<true/>
<key>lease_max</key>
<integer>86400</integer>
<key>lease_min</key>
<integer>86400</integer>
<key>name</key>
<string>192.168.33</string>
<key>net_address</key>
<string>192.168.33.0</string>
<key>net_mask</key>
<string>255.255.255.0</string>
<key>net_range</key>
<array>
<string>192.168.33.2</string>
<string>192.168.33.254</string>
</array>
</dict>
</array>
</dict>
</plist>
This file sets up the DHCP server to run on the interface named en0
, which is typically the (non-wireless) Ethernet port. It assumes that that port has been configured with the IP address 192.168.33.1
, and dishes out addresses from 192.168.33.2
to 192.168.33.254
.
To get more information on editing this file, take a look at the bootpd manfile:
man bootpd
To start the server, run the following command:
sudo /bin/launchctl load -w /System/Library/LaunchDaemons/bootps.plist
Stopping the server is very similar:
sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/bootps.plist
If you want to create static assignments, so that a given device always has the same IP address, you need to create a file called /etc/bootptab
. There's a small sample of the file below. For more information, just do man bootptab
%%
# machine entries have the following format:
#
# hostname hwtype hwaddr ipaddr bootfile
client1 1 00:01:02:03:04:05 10.0.0.20
client2 1 00:a0:b2:ef:ff:0a 10.0.0.20
Make sure to include the %%
at the top of the file. It's safe to leave the bootfile field empty because we're just using bootpd as a DHCP server, not a bootp server.