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