Create a configurable DHCPd that is NetBoot aware

Oct 17, '02 08:53:37AM

Contributed by: Anonymous

I'm working on a Mac OS X port of SystemImager, an automated software installation and distribution tool.

The first thing I needed was a configurable DHCP server that supports NetBooting.
I suspect bootp (aka DHCP) on Mac OS X Server does this, but I've never been able to figure out how to create statically assigned IP addresses assigned by MAC address. Gave up and replaced the built in bootp with the standards-based dhcpd from ISC, modified to support NetBoot, configured to sit cozy on Mac OS X.

Below are the directions, for anyone that might find it useful.

[Editor's note: I have not tested this hint myself, as it's well beyond my skill set! However, I don't see anything malicious in the script, and it might prove useful to some of you, so here it is...]

  1. Download dhcp-3.0pl1.tar.gz from Internet Software Consortium:
     % curl -O ftp://ftp.isc.org/isc/dhcp/dhcp-3.0pl1.tar.gz
  2. Unarchive the source:
     % tar zxvf dhcp-3.0pl1.tar.gz
  3. Downlaod the patch to make dhcpd netboot aware from Ron Lineweaver:
     % curl -O http://software.harrisonburg.k12.va.us/linux/
    src/dhcp-3.0-macnb-0.4.patch
    The above is shown on two lines; enter it as one with no spaces.

  4. Patch ISC's DHCP (enter the appropriate path for each file to patch):
     % mv dhcp-3.0pl1 dhcp-3.0-new
    % patch -p1 < dhcp-3.0-macnb-0.4.patch
  5. Configure, Build and Install modified DHCPd:
     % cd dhcp-3.0-new
    % ./configure
    % make
    % sudo make install
  6. Create an empty dhcpd leases file
     % touch /var/db/dhcpd.leases
  7. Add DHCP=-YES- to /etc/hostconfig entry

  8. Make StartupItem folders:
     % mkdir /Library/StartupItems
    % mkdir /Library/StartupItems/DHCP
    % mkdir /Library/StartupItems/DHCP/Resources
    % mkdir /Library/StartupItems/DHCP/Resources/English.lproj
  9. Make /Library/StartupItems/DHCP/DHCP. On my network, DHCP is being served by en0; modify "/usr/sbin/dhcpd en0" to taste:
    #!/bin/sh

    ##
    # DHCP
    ##

    . /etc/rc.common

    StartService ()
    {
    if [ "${DHCP:=-NO-}" = "-YES-" ]; then
    if ! pid=$(GetPID dhcpd); then
    ConsoleMessage "Starting DHCP services"
    /usr/sbin/dhcpd en0
    fi
    fi
    }

    StopService ()
    {
    if pid=$(GetPID dhcpd); then
    ConsoleMessage "Stopping DHCP services"
    kill -TERM "${pid}"
    else
    echo "dhcpd is not running."
    fi
    }

    RestartService ()
    {
    if pid=$(GetPID sendmail); then
    ConsoleMessage "Restarting DHCP services"
    kill -HUP "${pid}"
    else
    StartService
    fi
    }

    RunService "$1"
  10. Make /Library/StartupItems/DHCP/StartupParameters.plist:

    {
    Description = "DHCP server";
    Provides = ("DHCP");
    Requires = ("Network");
    Uses = ("Disks", "Network Time");
    OrderPreference = "None";
    }
  11. Make /Library -> StartupItems -> DHCP -> Resources -> English.lproj -> Localizable.strings:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist SYSTEM "file://localhost/System/
    Library/DTDs/PropertyList.dtd">
    <plist version="0.9">
    <dict>
    <key>Starting DHCP services</key>
    <string>Starting DHCP services</string>
    <key>Stopping DHCP services</key>
    <string>Stopping DHCP services</string>
    <key>Restarting DHCP services</key>
    <string>Restarting DHCP services</string>
    </dict>
    </plist>
    The "Doctype" line has been split in two for easier display; enter it as one line with no spaces.

  12. Set ownership and permissions:
     % chown -R root.wheel /Library/StartupItems/DHCP
    % chmod -R 755 /Library/StartupItems/DHCP
    % chmod 644 /Library/StartupItems/DHCP/StartupParameters.plist
  13. Make /etc/dhcpd.conf file (see man dhcpd.conf for details):
    default-lease-time 2592000;
    max-lease-time 2592000;
    ddns-update-style ad-hoc;
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.2.255;
    option routers 192.168.2.1;
    option domain-name-servers 192.168.2.1, 204.127.202.19;
    option domain-name "home.com";

    subnet 192.168.2.0 netmask 255.255.255.0 {
    range 192.168.2.2 192.168.2.100;
    }

    group {
    host tibook {
    hardware ethernet 00:30:65:10:76:0c;
    fixed-address 192.168.2.4;
    }
    }
  14. Finally, start the DHCP services:
     % sudo SystemStarter start DHCP
That's it!

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20021017055337617