freebsdzine.org
A great nation is any mob of people which produces at least one honest man a century.

[ Home  · Contribute  · Mailing Lists  · Contact Us  · Site Statistics  · Latest BSD News  · Submit an Article  ]

Search freebsdzine.org

FreeBSD 'zine Polls

I like...

men
women
men and women
pie
beer
uhhh, what?
moses

Results  · More polls


Sections
· Wanted articles
· About the site
· The staff
· Copyright info
· Privacy policy
· Change log

Resources
· The FreeBSD Project
· The FreeBSD Diary
· BSD Today
· Daemon News
· Daily Daemon News
· Slashdot BSD
· FreshPorts
· The FreeBSD Mall
· BSDVault
· The FreeBSD Browser

FreeBSD Books
· Complete FreeBSD
· FreeBSD Handbook
· FreeBSD Corporate
Networker's Guide


Runs on FreeBSD
Using DHCP
Chris Shumway <[email protected]>

The first step in configuring a DHCP server is to install one of the DHCP servers from the ports tree. The one I recommend and use is isc-dhcp3, which is in /usr/ports/net/isc-dhcp3.

Once that port is installed, visit /usr/local/etc, because you're going to make a configuration file named dhcpd.conf in that directory. Below is a skeleton configuration file.

Initial DHCP Configuration

The syntax of the dhcpd.conf file is very familiar if you are a C/C++ programmer. Sections are broken up by braces, and lines are terminated by semi-colons.

shared-network DHCP-NET {
	option domain-name "example.net";
	option netbios-name-servers "foo.example.net";
	option nis-domain "example.net";
	use-host-decl-names on;
	default-lease-time 600;
	max-lease-time 3600;
	subnet 192.168.0.0 netmask 255.255.255.0 {
		option broadcast-address 192.168.0.255;
		option domain-name-servers 192.168.0.1;
		option subnet-mask 255.255.255.0;
		option routers 192.168.0.1;
		range 192.168.0.32 192.168.0.254;
	}
}

This defines the necessary options for the 192.168.0.0 network with a netmask of 255.255.255.0 to allow dynamic configuration of hosts on the network.

Here's a quick rundown of the options present:

option domain-name
This is the domain name that the machines on the network will be part of.
 
option netbios-name-servers
This option describes the NetBIOS Browse Master for the network. This is only useful if there are Windows 9X/NT/2000 machines on the network.
 
option nis-domain
This is the domain name for the NIS master server. This is only useful if NIS is used on the network.
 
use-host-decl-names
This, when set to ON, allows static hosts to acquire their hostname from the DHCP server given their static entry (more on static entries below).
 
default-lease-time
This is the time, in seconds, until a client's DHCP lease can expire. I personally set this to a lower value so any changes I make will take effect faster. Keep in mind that doing so increases network traffic.
 
max-lease-time
This is the maximum lease time a system can "hold" a DHCP address.
 
subnet IP netmask MASK
This defines a subnet that the server is going to be providing DHCP services for. It takes IP, which is the IP address of the network, and MASK, which is the netmask for the network.

The following options sit inside a subnet definition:

option broadcast-address
This is the broadcast IP address for the subnet.
 
option domain-name-servers
This is the IP address of the DNS server(s) for the network. If you have more than one, then you can separate them with commas.
 
option subnet-mask
This is the netmask for the network in question.
 
option routers
The default gateway for the network goes here.
 
range START END
This defines the range of IP addresses that can be used for the dynamic configuration pool. Every IP address in this range will be given dynamically to hosts that do not have a static entry.
Static Host Configuration

You can define hosts that get configured by DHCP, but will always get the same IP address. To do this, add an entry for every host in the shared-network section, like so:

shared-network DHCP-NET {
	option domain-name "example.net";
	option netbios-name-servers "foo.example.net";
	option nis-domain "example-net";
	use-host-decl-names on;
	default-lease-time 600;
	max-lease-time 3600;
	subnet 192.168.0.0 netmask 255.255.255.0 {
		option broadcast-address 192.168.0.255;
		option domain-name-servers 192.168.0.1;
		option subnet-mask 255.255.255.0;
		option routers 192.168.0.1;
		range 192.168.0.32 192.168.0.254;
	}
	host foobar {
		option host-name "foobar.example.net";
		hardware ethernet 00:a0:d2:18:84:49;
		fixed-address foobar.example.net;
	}

This will create a static entry for host foobar.example.net. Note that foobar.example.net needs to exist in the DNS server for this to work.

Here are the options available:

option host-name
The name of the client, as listed in the DNS records for the network.
 
hardware ethernet
The hardware's MAC address. This is used by DHCP to determine the host before it assigns it an IP address.
 
fixed-address
This is the address or hostname that the given host will receive when it comes up and asks for a DHCP lease.

Once you set up the config file, you can start dhcpd from a script in /usr/local/etc/rc.d. Here's the startup script I use:

#!/bin/sh
case "$1" in
  start)
    if [ -x /usr/local/sbin/dhcpd ] && \
      [ -f /usr/local/etc/dhcpd.conf ]
      then echo -n " dhcpd"
      /usr/local/sbin/dhcpd -q -cf /usr/local/etc/dhcpd.conf fxp0
      exit 0
      fi
    exit 1
    ;;
  stop)
    ;;
  *)
    echo "usage: `basename $0` (start|stop)" >&2
    exit 64
    ;;

Be sure to replace the interface (fxp0) with the network interface for your system.

You can test your configuration at this point by running:

/usr/local/sbin/dhcpd -cf /usr/local/etc/dhcpd.conf interface

Replace interface with the network interface that dhcpd will be listening on.

Also, if you get any configuration errors, be sure that your semi-colons and braces are all there because dhcpd is really picky about them.

- Chris

Return to the February 2001 Issue



Issues
2001
· March
· February
· January

2000
· December
· August
· July
· June
· May
· April
· March
· February

1999
· January

Other issues from 1999 are available in the attic for now.

Other News
· Slashdot
· FreeBSD Diary
· BSD Today
· FreshPorts
· Daemon News
· OS Online
· Rootprompt
· Maximum BSD

Miscellaneous
· Jim's site

IRC
#freebsdzine
If you'd like to hang out with us and talk about the site, join us in #freebsdzine on Undernet.

Backend
You can add a list of our latest issue's articles to your site by using our RDF/RSS file. You can also add it to your My Netscape page, or add our slashbox once you log in over at Slashdot.

[ Home  · Contribute  · Mailing Lists  · Contact Us  · Site Statistics  · Latest BSD News  · Submit an Article  ]

Copyright © 1998-2001 · The FreeBSD 'zine · All rights reserved.