[HOWTO] - Setup DHCPD (Server) on Mac OS X (Workstation)

Discussion in 'HOWTO & FAQs' started by kilowatt, Mar 1, 2002.

  1. kilowatt

    kilowatt mach-o mach-o man

    Joined:
    Mar 25, 2001
    Messages:
    983
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    father, RF / DigiComm Engineer
    Ok, this is for those of you who want to set up a DHCP server to allow other computers to grab ip and dns information off of your computer. This is especially useful if you have a small private network and wish to automate the addition of other computers.

    For this howto, basic terminal skills and admin-level access are required. Its not hard, don't worry :p

    BTW, if you allready have a dhcp server on the network, turn it off first :)

    First, go to the official DHCP web page and have a look around:
    http://isc.org/products/DHCP/
    here's the source code - download it by control-clicking the link and selecting 'save as...'
    ftp://ftp.isc.org/isc/dhcp/dhcp-latest.tar.gz
    Now, logged in as an admin-level user, open the Terminal (located in /Applications/Utilities)
    type the following commands:
    Code:
    cd /path/to/the/file/you/downloaded
    tar -zxvf dhcp-latest.tar.gz
    cd dhcp-3.0
    ./configure
    make
    [i]get food or something - takes about 3 mins to compile - oh btw, when prompted for a password, enter [b]your[/b] password[/i]
    cd work.darwin
    cd server
    sudo make install
    cd ../common
    sudo make install
    cd ../dhcpctl
    sudo make install
    cd ../opamip
    sudo make install
    
    thats it! now you have the binaries for the server, as well as some dhcp-tweaking utilities installed. If you're nuts, you can simply:
    Code:
    sudo make install
    
    in the dhcp-3.0 directory - but be warned - you are replacing existing Mac OS X dhcp client files as well, and I don't recommend this. (If you do this, and it works though, please post, I'm sure many would like to update their dhcp clients too).

    Now, we have to configure the server. Still to go is making it startup on startup :p

    cd into /etc
    cd /etc
    ok, now type sudo pico dhcpd.conf
    This is the dhcpd configuration file (duh).
    Here is a URL I found extremely helpful at this point: http://www.linux-mag.com/2000-04/networknirvana_03.html
    the next page in the url is also helpful.

    For the impatient, here is a copy of my /etc/dhcpd.conf file - just paste it into pico.
    Code:
    ## /etc/dhcpd.conf file
    ## compiled by the infamous super-hacker unix guru kilowatt from macosx.com (you need this in the file for things to work :p )
    option domain-name-servers 192.168.1.140;
    ddns-update-style ad-hoc;
    subnet 192.168.1.0 netmask 255.255.255.0 {
    
    range 192.168.1.150 192.168.1.200;
    default-lease-time 300000;
    max-lease-time 350000;
    option routers 192.168.1.1;              
    }
    
    if you're in pico like me (vi sucks btw) press control-o, then hit return to save the file.

    ok, now before we start the dhcpd, we need to touch up a fake database file so that dhcpd will think its been ran before. I think its rather stupid that we have to do this, and there's probably a way around it, but for now, whatever :)

    Code:
    sudo touch /var/db/dhcpd.leases
    
    okey dokey, now we're set. Here's how you start the server:
    sudo dhcpd &

    more to follow on starting it automatically and netinfo integration.
     
  2. kilowatt

    kilowatt mach-o mach-o man

    Joined:
    Mar 25, 2001
    Messages:
    983
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    father, RF / DigiComm Engineer
    updates:

    1) every /etc/dhcpd.conf file on the internet is wrong - type mine *exactly* as it appears caus dhcpd is very picky apparently. Especially important is the semi-colin

    2) To start the dhcpd server on an interface other than your default gateway (which is highly desireable on dual-interface configurations used as an internet gateway), start dhcpd like this:
    Code:
    sudo dhcpd en1
    
    see ifconfig -a for a list of interfaces.

    3) the man page for dhcpd (man dhcpd) is wonderful. Stop by there before you search yahoo or google.

    enjoy the dhcp server, please ask if you have any questions.

    Oh, and btw, adjust the config file to your preferences - if you don't have a dns server at 192.168.1.140, for example, don't say you have one (but put your isp's dns server there).
     
  3. kilowatt

    kilowatt mach-o mach-o man

    Joined:
    Mar 25, 2001
    Messages:
    983
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    father, RF / DigiComm Engineer
    ok, ate some food, read some of 'An AIX Companion" (circa 1994 written by David L. Cohn), banged my head against the wall, read some more, and came up with a macintosh startup script. Pretty cool, huh?


    ok, so here's what to do:
    in the terminal as an admin-level user:
    Code:
    cd /Library
    mkdir StartupItems
    [i]skip that step if its allready there - check by typing ls[/i]
    sudo chown root:admin StartupItems
    [i]if you trust all your wheel (admin) users to be smart people, you can leave it owned to wheel (the default)[/i]
    
    ok now download my file :)
    and move it and unstuff:
    Code:
    sudo mv ~/Downloads/dhcpd-startup.zip .
    sudo unzip dhcpd-startup.zip
    sudo rm dhcpd-startup.zip
    
    thats it!

    it should create a directory called 'dhcpd'. Poke around in it to see how it works.

    If you want, you can do this in /System/Library/StartupItems, but apple requests that you put it in /Library so that it isn't confused with apple's startup stuff.

    Thanks to Yoshi, IckyShuff, twyg and Julian for putting up with me and supporting this in #macintosh - without them this would not be here.


    btw, admin, can you allow us to post .tar.gz files? I had to learn how to use the 'zip' command (which was incredibly hard) and I had to figure out that zip -x doesn't unzip :) only unzip does :p
     

    Attached Files:

  4. natethelen

    natethelen Registered

    Joined:
    Feb 5, 2002
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Your ZIP file is empty. Can you post another file that works (or maybe copy th source into the message)

    Thanks,
    Nate
     
  5. kilowatt

    kilowatt mach-o mach-o man

    Joined:
    Mar 25, 2001
    Messages:
    983
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    father, RF / DigiComm Engineer
    yeah, I'll post one later on tonight!

    probably has to do with the thread being moved from UNIX discussion to the Archive.
     
  6. kilowatt

    kilowatt mach-o mach-o man

    Joined:
    Mar 25, 2001
    Messages:
    983
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    father, RF / DigiComm Engineer
    File no longer available

    download the file (use the 'save link as...' thing, don't just click it, we don't want Stuffit Expander doing anything).

    now, in the terminal:
    Code:
    cd /Library/StartupItems
    cp ~/Desktop/dhcpd-startup.tar.gz .
    tar -xzvf dhcpd-startup.tar.gz
    rm dhcpd-startup.tar.gz
    
    thats it!

    enjoy :)
     
    Last edited by a moderator: Jan 13, 2009
  7. doemel

    doemel Mac addict since 1993

    Joined:
    Feb 26, 2002
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    environmental scientist
    Location:
    Zurich, Switzerland
    I have tried to install the latest version (3.0p1) on the latest OS X release (10.2.1) and all I get is error messages. When I enter ./configure I get the following list of error messages:

    Making links in common
    ln: raw.c: No such file or directory
    ln: parse.c: No such file or directory
    ln: nit.c: No such file or directory
    ln: icmp.c: No such file or directory
    ln: dispatch.c: No such file or directory
    ln: conflex.c: No such file or directory
    ln: upf.c: No such file or directory
    ln: bpf.c: No such file or directory
    ln: socket.c: No such file or directory
    ln: lpf.c: No such file or directory
    [... I have cut some lines that are similar to these...]
    ln: discover.c: No such file or directory
    ln: comapi.c: No such file or directory
    ln: dhcp-options.5: No such file or directory
    ln: dhcp-eval.5: No such file or directory
    make[2]: *** [links] Error 1
    make[1]: *** [links] Error 1
    make: *** [links] Error 2


    Amd when, after that, I try to make I get the following:

    Making all in common
    make[2]: *** No rule to make target `raw.o', needed by `libdhcp.a'. Stop.
    make[1]: *** [all] Error 1
    make: *** [all] Error 2


    Can anyone help me with this and/or update the instructions for 10.2.1 and the latest release of DHCP?

    Dominik Schmid
     
  8. kilowatt

    kilowatt mach-o mach-o man

    Joined:
    Mar 25, 2001
    Messages:
    983
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    father, RF / DigiComm Engineer
    Do you have the developer tools installed (the latest ones?). You'll need those.
     
  9. bing

    bing Registered

    Joined:
    Nov 17, 2002
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Sys Admin
    Location:
    Australia
    Just a note with starting the server, you might need to mention the network adapter to listen on

    something like -

    dhcpd & ne0
     
  10. jakerollo

    jakerollo Registered

    Joined:
    Dec 5, 2002
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    When i try to start the dhcpd (sudo dhcpd en1) i am told that "No subnet declaration for en1 (my ip)".

    What could this mean and how do i fix it?
     
  11. jakerollo

    jakerollo Registered

    Joined:
    Dec 5, 2002
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Problem solved.

    But a new one has just entered the door.

    The startup script does not seem work properly for me. It is not a problem starting the script manually but even though it tries (i can see that on the startup screen) it is not started successfully.

    I do not know where to begin looking for the reason to this problem so maybe someone could guide me here?
     
  12. bing

    bing Registered

    Joined:
    Nov 17, 2002
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Sys Admin
    Location:
    Australia
    For the subnet problem check that the subnet declared is consistent with your IP address.

    Also make sure there is a network attatched to the ethernet port, my ibook's network port doestn become active uinless its pluged in, thus the DHCP server cant start if the network port is not active.
     
  13. mmpete

    mmpete Registered

    Joined:
    Mar 8, 2005
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I had exactly the same problem with installation - the path to the directory I was trying to compile DHCP in had spaces. The easiest way around this is to try creating a symbolic link with spaces replaced by some other character - eg:

    >pwd
    /Rootdir/lots of spaces/dhcp-3.0.2
    >cd /Rootdir
    >ln -s "lots of spaces" lots_of_spaces
    >cd lots_of_spaces/dhcp-3.0.2
    >pwd
    /Rootdir/lots_of_spaces/dhcp-3.0.2

    Then run ./configure again, and it should all work!

    HTH,
    Alastair
     
  14. chrispy987

    chrispy987 Registered

    Joined:
    Jun 12, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Thanks to kilowatt for getting me started on this. My solution is pretty barbones, but it works for me.


    1. Download the DHCP code from http://www.isc.org/.

    2. Expand the package. I used /sbin as the directory.
    sudo tar xcvf dhcp-X.XX

    3. Change in to the new directory.

    4. Build and install the package.
    sudo ./configure
    sudo make
    sudo make install

    5. Add dhcp.plist to /System/Library/LaunchDaemons
    Code:
    <?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/sbin/dhcpd</string>
    	</array>
    	<key>RunAtLoad</key>
    	<true/>
    	<key>UserName</key>
    	<string>root</string>
    </dict>
    </plist>
    
    This is configured to launch on start up.

    6. Configure dhcpd.conf
    Here's a verison of what I used: Sample 1
    Code:
    ## /etc/dhcpd.conf file 
    ## compiled by the infamous super-hacker unix guru kilowatt from macosx.com (you need this in the file for things to work :p )
    ## tweaked for fixed addresses by Chrispy.
    
    
    option domain-name "Your_domain.com";
    option domain-name-servers 66.66.77.88, 66.66.77.89;
    
    ##Check ddns?
    ddns-update-style ad-hoc;
    
    
    Authoritative;
    
    ##define the Subnet to be served.
    
    subnet 192.168.1.0 netmask 255.255.255.0 {
    
    ##Define the DHCP address range to be served.
    
    range 192.168.1.50 192.168.1.90;
    default-lease-time 300000;
    max-lease-time 350000;
    option routers 192.168.1.1; 
    }
    
    
    ## Fixed IP addresses the name isn't too important.  Just match the MAC address (hardware ethernet) the fixed-address to use.  Watch the semicolons.
    host comp1 {
      hardware ethernet 00:11:22:33:44:55;
      fixed-address 192.168.1.2;
    }
    
    host comp2 {
      hardware ethernet 00:aa:bb:cc:dd:ee;
      fixed-address 192.168.1.3;
    }
    
    host comp3 {
      hardware ethernet 00:ee:dd:cc:bb:aa;
      fixed-address 192.168.1.4;
    }
    
    host router {
      hardware ethernet 00:aa:11:bb:22:cc;
      fixed-address 192.168.1.1;
    }
    

    Now dhcp should be availalbe using the service command, and you should be able to start and stop it normally. It should also launch at start up. If you want to turn it off, just edit the .plist.
     

    Attached Files:

  15. scruffy

    scruffy Notorious Olive Counter

    Joined:
    Dec 6, 2000
    Messages:
    1,725
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Soviet Canuckistan
    There's also the option of using bootpd, which is included in OS X. Did you find a deficiency in bootpd where ISC's dhcpd was better?

    If not, would a howto on setting up dhcp services with bootpd be helpful?
     
  16. mlawson66

    mlawson66 Registered

    Joined:
    Aug 7, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    So, I'm trying to share my internet connection via the built in wireless connection on my powerbook. A couple people with Linux laptops have tried to connect, but only people with macs have met with success. It appears that DHCP requests aren't being answered. So, I tried the steps detailed in this thread, but dhcpd can not bind to the interface...

    <snip>
    frisbee:/etc root# dhcpd en1
    Internet Systems Consortium DHCP Server V3.0.4
    Copyright 2004-2006 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/
    Wrote 0 leases to leases file.
    Listening on BPF/en1/00:0a:95:f4:fa:fe/10.0.2/24
    Sending on BPF/en1/00:0a:95:f4:fa:fe/10.0.2/24
    Can't bind to dhcp address: Address already in use
    Please make sure there is no other dhcp server
    running and that there's no entry for dhcp or
    bootp in /etc/inetd.conf. Also make sure you
    are not running HP JetAdmin software, which
    includes a bootp server.
    </snip>


    Any ideas on how to get this thing to hand out DHCP over the wireless connection?

    OS X 10.4.7, 15" Aluminum Powerbook 1.25 GHz.

     
  17. picosucks

    picosucks Registered

    Joined:
    Jul 7, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I hope in the last 8 years you've managed to realize that not only is editing config files with pico a noob mistake.. bashing vi in the same post is even worse.
     
  18. doemel

    doemel Mac addict since 1993

    Joined:
    Feb 26, 2002
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    environmental scientist
    Location:
    Zurich, Switzerland
    no, vi does suck and this has nothing to do with n00b. it's just 1337 or wanna be 1337 brag-a-thon-ware that makes any UI designer wanna kill your kitten.
     
  19. ElDiabloConCaca

    ElDiabloConCaca U.S.D.A. Prime

    Joined:
    Aug 22, 2001
    Messages:
    14,524
    Likes Received:
    16
    Trophy Points:
    38
    Gender:
    Male
    Occupation:
    CTO
    Location:
    San Antonio, Texas
    I believe that's why they came out with vim, or "vi improved."

    BTW, nano schools all you n00b's text editors several times over. ;)
     
  20. doemel

    doemel Mac addict since 1993

    Joined:
    Feb 26, 2002
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    environmental scientist
    Location:
    Zurich, Switzerland
    vim? just the same tired old fart in slighly newer clothing.

    i'll take nano, pico over any vi variant anyday. what you think you'll get is what you'll get. not what you think you'll get will
    a) destroy your text
    b) quit with unsaved changes
    c) overwrite your precious default config with garbage that you accidently entered yourself
     

Share This Page