The DHCP server
|
Where to find a DHCP server?
The Internet Software Consortium develops a free DHCP server for
Unix-like system. This is the most spread server and the one that respects at best RFCs. The latest
version is 3.0 but it is still a beta version. previous versions are working very well, even if the
ISC releases regular patches. One of the most interesting innovation of the version 3 is the possibility
to dynamically update a DNS server so that IP addresses and names perfectly match. Actually the first
draft for this feature was released in march 1996 and it is not properly implemented yet...
To know more about dynamic DNS update.
Obviously, Microsoft has its own DHCP server for Windows, but only the version for Windows 2000 Server
can dynamically update DNS. Microsoft already had such a feature but for its proprietary name system
using a WINS server.
What follows in this page deals with the installation and configuration of the ISC DHCP server under
a Unix-like system.
Compiling the server
This is the very first thing to do once you have downloaded the sources.
Visit and download a DHCP server from the ISC web site, or
simply this version that implements in a tricky way
the dynamic DNS update feature. Copy this file in a directory.
Uncompress the archive: tar xzf dhcp-2.0pl5.tar.gz
A new directory is created. Go into it (with cd) and type: ./configure
This prepares the Makefile files corresponding to your system. Now, type: make
to compile the server. Finally, type: make install to definitely install the DHCP server
at the right place on your system.
Before typing ./configure, it is highly advised to read the README file that explains
in a deeper way how to install the server. For instance with the version provided on this web site,
you could learn how to compile the server so that it will update a DNS server: type ./configure --with-nsupdate
to build a server with dynamic DNS update support. make install will copy some perl scripts
in the /usr/local/DHCP-DNS-0.52mdn.
dhcpd.conf
This file is used to configure the server. By default, it is located in /etc but it
is possible to put it somewhere else. It is made up of several sections, some of them delimited with
braces ({ and }):
- global parameters,
shared-network { ... },
subnet { ... },
host { ... },
group { ... }.
Every section may contain parameters and options. A group section
may contain several host sections. At the very beginning of the file, one can write global
parameters, such as the lease duration, that will be used for the rest of the configuration.
Every line of this file must end with a ;, unless there is a brace.
Comments are allowed with a # at the beginning of the line.
Global parameters
Nearly everything can be used as a global parameters, provided that they have a real meaning for
the configuration in a whole. For instance, it is possible to define the duration for leases
(max-lease-time and default-lease-time), avoid the server to reply to
messages from undeclared hosts (deny unknown-clients;), give the domain name, DNS
servers addresses... See an example.
shared-network
This statement is used to gather several subnet sections when they are sharing the
same physical network. Parameters provided at the beginning of the statement will be used for
booting hosts, unless you use host sections to prevent the server to reply for these
hosts. It is recommended to use it every time several subnet sections concern the
same physical network.
Syntax:
shared-network FOO-BAR {
filename "boot";
subnet 192.168.2.0 netmask 255.255.255.224 {
range 192.168.2.10 192.168.2.30;
}
subnet 192.168.2.32 netmask 255.255.255.224 {
range 192.168.2.40 192.168.2.50;
}
}
subnet
This section is used to define subnetworks on which the DHCP server must intervene. It is maybe the
most important part of the configuration file: without them, the server will never work.
The syntax is the following:
subnet subnet_address netmask netmask {
[ global parameters... ]
[ declarations... ]
}
subnet_addess and netmask are formatted in the IP address way (255.255.248.0
for instance). There is an example above.
It is obviously possible to use global parameters that should be valid only for computers from
this subnet. For instance, we can give the domain name for this subnet (option domain-name).
We can use host statements.
The most important global parameter is range: range [ dynamic-bootp ] lower_address [ upper_address ];
that defines the range of IP addresses the server can distribute for this subnet. We can use several
range parameters if needed. If we do not give any upper-range address, the DHCP server will use
only lower one. dynamic-bootp must be used to ask the server to reply to BOOTP request
with an address from this range.
host
This statement is used to define host typical parameters. This section is not mandatory but it
can be useful if there is a deny unknown-clients; at the beginning of the file to give
a sense to the DHCP server (it will never work, otherwise).
host is used like this:
host name {
parameters...
}
A host may be recognized by 2 ways: whether by its name (the name that comes just after host)
or by its hardware address (ethernet or token-ring). In this latter case, one must add a line in the
host statement: hardware ethernet|token-ring adresse-hardware;.
It is highly recommended to identify hosts using their hardware address rather than using their name,
all the more so they are not supposed to have a name and this name may change. However, the name
provided after host can be internally used in the configuration file as an indentifier.
Important point: we must use a host statement if we want the DHCP server to allocate
a fixed IP address to a given host: fixed-address 192.168.2.4;. Obviously, such
IP addresses must be removed in the range... parameters.
group
It is just used to gather host statement to apply a common set of global parameters:
group {
option domain-name "bar.org";
option routers 192.168.1.254;
host foo1 {
...
}
host foo2 {
...
}
}
Options
Parameter lines beginning with "option" are options defined in RFC2132.
There are only about 60 options defined in this RFC, even if it is possible to have up to 254 options
(options 0 and 255 are reserved). To find the complete list of options and their names, you can check
the file common/tables.c located in the sources of the server. Be careful, names can vary
from one version to another.
The most common options are the following ones:
subnet-mask (option 1) is used to give the subnet-makc value to the client.
routers (option 3) that points out routers and gateways.
domain-name-servers (option 6) that points out the DNS servers. It is possible
to give the names of the DNS servers as well as their IP addresses.
host-name (option 12) is used to give its name to a host.
domain-name (option 15) that points out the domain name.
broadcast-address (option 28) is used to tell the broadcast address available
on the local network.
dhcp-lease-time (option 51) is used to tell how long the lease is valid.
Other options (60 in particular) can be used to personalize a DHCP message.
Complete example for dhcpd.conf
max-lease-time 240;
default-lease-time 240;
deny unknown-clients;
option domain-name "bar.com";
option domain-name-servers foo1.bar.com, foo2.bar.com;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.2 192.168.1.100;
range 192.168.1.110 192.168.1.254;
option broadcast-address 192.168.1.255;
}
group {
option routers 192.168.2.101;
host foo3 {
hardware ethernet 00:c0:c3:11:90:23;
option host-name pc3;
}
host foo4 {
hardware ethernet 00:c0:c3:cc:0a:8f;
fixed-address 192.168.1.105;
}
}
host foo5 {
hardware ethernet 00:c0:c3:2a:34:f5;
server-name "bootp.bar.com";
filename "boot";
}
Explanation:
The first 5 lines define global parameters. The first 2 ones deal with leases. The next line asks
the server not to reply to DHCP messages from unknown hosts (i.e. not declared in dhcpd.conf). Finally,
we define global parameters for the network (domain name and DNS servers).
Then, we define the subnetwork with which the DHCP server should work; it is the line starting
with "subnet...". In this subnet, we would like the server to distribute IP addresses in 2 specific
ranges ("range..."). The last line of the subnet statement defines the broadcast address that should
be used by DHCP clients for this subnet.
Then we create a group whose unique role is to give a gateway address to some specific machines
(recognized thanks to their MAC addresses). Let's notice that foo4.bar.com should get a fixed address.
Finally, foo5 is a machine that will boot remotely, connecting to the server called bootp.bar.com
and asking for the file "boot".
Starting the dhcpd daemon
To start the server, you must be root on the system. Then, you have to use this command line:
dhcpd -lf lease_database -cf config_file adpater1 adapter2...
The DHCP server is requested to work on the network adapters adapter1, adapter2... The server will
also find its configuration in the "config_file" file, and will use the file
"lease_database" to store the leases it will grant. If no arguments are provided, the
DHCP server will look for its default files, i.e. those specified at the compilation process in the
includes/dhcpd.h file, and will use eth0 as a unique network adapter to work on. Of
course, it is possible to change all these parameters.
How to start automatically the server when the server boots?
To make the DHCP server start when your server machine boots, you need to add a launching script
in /etc/rc.d/init.d/. This script will be actually used to start and stop the daemon.
This file is actually not provided in the ISC package, so you have to write it by yourself by
taking example on those that are already in this directory. Nevertheless, you can simply use
this one. Check it to give the correct parameter. Do a chmod 755 dhcpd
to set the rights.
Now, you have to ask Linux to use this script at its boot process. This is performed by creating
symbol links in /etc/rc.d/rcx.d/ where x is an enteger that represents the level at
which the server should be started or stopped. However, with a correctly written script, you will just
have to execute: chkconfig --add dhcpd and all the right symbol link will be created.
You can now start you machine and the DHCP server will start automatically.
WARNING! linuxconf may take control of your server. If you do not want linuxconf to do that,
you will have to tell it not to do so (start its configuration tool and look in the menu).
Documentation
make install should have copied standard manual pages onto your system. To access
them type:
man dhcpd to learn how dhcpd works,
man dhcpd.conf to learn a bit more about writting a perfect dhcpd.conf file,
man dhcpd.leases to know more about leases and the lease database format.
This documentation is unfortunately not complete or simple; for instance, DHCP options
are not detailed. The best thing to learn a lot, but it is tedious, is to read the RFCs which, for
once, are quite clear and simple.
printable format
|