Dynamic Host Configuration Protocol (DHCP) server
dhcpd [-p port] [-f] [-d] [-q] [-t|-T] [-4|-6] [-s server] [-cf config-file] [-lf lease-file] [-pf pid-file] [-tf trace-output-file] [-play trace-playback-file] [ if0 [ ...ifN ] ] dhcpd --version
QNX Neutrino
IPv4 name | IPv6 name |
---|---|
dhcpd.conf | dhcpd-dhcpv6.conf |
dhcpd.leases | dhcpd6.leases |
dhcpd.pid | dhcpd6.pid |
The Internet Systems Consortium DHCP Server, dhcpd, implements the Dynamic Host Configuration Protocol (DHCP) and the Internet Bootstrap Protocol (BOOTP). DHCP allows hosts on a TCP/IP network to request and be assigned IP addresses, and also to discover information about the network to which they are attached. BOOTP provides similar functionality, with certain restrictions.
The DHCP protocol allows a host which is unknown to the network administrator to be automatically assigned a new IP address out of a pool of IP addresses for its network. In order for this to work, the network administrator allocates address pools in each subnet and enters them into the dhcpd.conf(5) file.
On startup, dhcpd reads the dhcpd.conf file and stores a list of available addresses on each subnet in memory. When a client requests an address using the DHCP protocol, dhcpd allocates an address for it. Each client is assigned a lease, which expires after an amount of time chosen by the administrator (by default, one day). Before leases expire, the clients to which leases are assigned are expected to renew them in order to continue to use the addresses. Once a lease has expired, the client to which that lease was assigned is no longer permitted to use the leased IP address.
In order to keep track of leases across system reboots and server restarts, dhcpd keeps a list of leases it has assigned in the dhcpd.leases file. Before dhcpd grants a lease to a host, it records the lease in this file and makes sure that the contents of the file are flushed to disk. This ensures that even in the event of a system crash, dhcpd will not forget about a lease that it has assigned. On startup, after reading the dhcpd.conf file, dhcpd reads the dhcpd.leases file to refresh its memory about what leases have been assigned.
New leases are appended to the end of the dhcpd.leases file. In order to prevent the file from becoming arbitrarily large, from time to time dhcpd creates a new dhcpd.leases file from its in-core lease database. Once this file has been written to disk, the old file is renamed dhcpd.leases~, and the new file is renamed dhcpd.leases. If the system crashes in the middle of this process, whichever dhcpd.leases file remains will contain all the lease information, so there is no need for a special crash recovery process.
BOOTP support is also provided by this server. Unlike DHCP, the BOOTP protocol doesn't provide a protocol for recovering dynamically-assigned addresses once they are no longer needed. It is still possible to dynamically assign addresses to BOOTP clients, but some administrative process for reclaiming addresses is required. By default, leases are granted to BOOTP clients in perpetuity, although the network administrator may set an earlier cutoff date or a shorter lease length for BOOTP leases if that makes sense.
BOOTP clients may also be served in the old standard way, which is to simply provide a declaration in the dhcpd.conf file for each BOOTP client, permanently assigning an address to each client.
Whenever changes are made to the dhcpd.conf file, dhcpd must be restarted. To restart dhcpd, send a SIGTERM (signal 15) to the process ID contained in /var/run/dhcpd.pid, and then reinvoke dhcpd. Because the DHCP server database isn't as lightweight as a BOOTP database, dhcpd doesn't automatically restart itself when it sees a change to the dhcpd.conf file.
Command line
The names of the network interfaces on which dhcpd should listen for broadcasts may be specified on the command line. This should be done on systems where dhcpd is unable to identify non-broadcast interfaces, but shouldn't be required on other systems. If no interface names are specified on the command line dhcpd will identify all network interfaces which are up, eliminating non-broadcast interfaces if possible, and listen for DHCP broadcasts on each interface.
The server either operates as a DHCPv6 server or a DHCP server, but not both at the same time. To run as a DHCPv6 server, use the -6 flag. To run as a DHCP server, use the -4 flag. If neither is used, the default is to run as a DHCPv6 server.
If dhcpd should listen on a port other than the standard (port 67), the -p flag may used. It should be followed by the UDP port number on which dhcpd should listen. This is mostly useful for debugging purposes.
If dhcpd should send replies to an address other than the broadcast address (255.255.255.255), the -s flag may be used. It is followed by either the IP address or the host name to send replies to. This option is supported only in IPv4.
To run dhcpd as a foreground process, rather than allowing it to run as a daemon in the background, the -f flag should be specified. This is useful when running dhcpd under a debugger, or when running it out of inittab on System V systems.
To have dhcpd log to the standard error descriptor, specify the -d flag. This can be useful for debugging, and also at sites where a complete log of all DHCP activity must be kept, but syslogd isn't reliable or otherwise cannot be used. Normally, dhcpd will log all output using the syslog() function with the log facility set to LOG_DAEMON. Note that -d implies -f (the daemon will not fork itself into the background).
You can make dhcpd use an alternate configuration file with the -cf flag, an alternate lease file with the -lf flag, or an alternate pid file with the -pf flag. Because of the importance of using the same lease database at all times when running dhcpd in production, these options should be used only for testing lease files or database files in a non-production environment.
When starting dhcpd up from a system startup script (e.g., /etc/rc), it may not be desirable to print out the entire copyright message on startup. To avoid printing this message, the -q flag may be specified.
The DHCP server reads two files on startup: a configuration file, and a lease database. If the -t flag is specified, the server will simply test the configuration file for correct syntax, but will not attempt to perform any network operations. This can be used to test the a new configuration file automatically before installing it.
The -T flag can be used to test the lease database file in a similar way.
The -tf and -play options allow you to specify a file into which the entire startup state of the server and all the transactions it processes are either logged or played back from. This can be useful in submitting bug reports—if you are getting a core dump every so often, you can start the server with the -tf option and then, when the server dumps core, the trace file will contain all the transactions that led up to it dumping core, so that the problem can be easily debugged with -play.
The -play option must be specified with an alternate lease file, using the -lf switch, so that the DHCP server doesn't wipe out your existing lease file with its test data. The DHCP server will refuse to operate in playback mode unless you specify an alternate lease file.
To find the version of dhcpd that will run, use the --version argument. Instead of running, the version will be displayed.
Configuration
The syntax of the dhcpd.conf file is discussed separately. This section should be used as an overview of the configuration process, and the dhcpd.conf documentation should be consulted for detailed reference information.
Subnets
The dhcpd server needs to know the subnet numbers and netmasks of all subnets for which it will be providing service. In addition, in order to dynamically allocate addresses, it must be assigned one or more ranges of addresses on each subnet which it can in turn assign to client hosts as they boot. Thus, a very simple configuration providing DHCP support might look like this:
subnet 239.252.197.0 netmask 255.255.255.0 { range 239.252.197.10 239.252.197.250; }
Multiple address ranges may be specified like this:
subnet 239.252.197.0 netmask 255.255.255.0 { range 239.252.197.10 239.252.197.107; range 239.252.197.113 239.252.197.250; }
If a subnet will only be provided with BOOTP service and no dynamic address assignment, the range clause can be left out entirely, but the subnet statement must appear.
Lease lengths
DHCP leases can be assigned almost any length from zero seconds to infinity. What lease length makes sense for any given subnet, or for any given installation, will vary depending on the kinds of hosts being served.
For example, in an office environment where systems are added from time to time and removed from time to time, but move relatively infrequently, it might make sense to allow lease times of a month of more. In a final test environment on a manufacturing floor, it may make more sense to assign a maximum lease length of 30 minutes - enough time to go through a simple test procedure on a network appliance before packaging it up for delivery.
It is possible to specify two lease lengths: the default length that will be assigned if a client doesn't ask for any particular lease length, and a maximum lease length. These are specified as clauses to the subnet command:
subnet 239.252.197.0 netmask 255.255.255.0 { range 239.252.197.10 239.252.197.107; default-lease-time 600; max-lease-time 7200; }
This particular subnet declaration specifies a default lease time of 600 seconds (ten minutes), and a maximum lease time of 7200 seconds (two hours). Other common values would be 86400 (one day), 604800 (one week) and 2592000 (30 days). Each subnet need not have the same lease--in the case of an office environment and a manufacturing environment served by the same DHCP server, it might make sense to have widely disparate values for default and maximum lease times on each subnet.
BOOTP support
Each BOOTP client must be explicitly declared in the dhcpd.conf file. A very basic client declaration will specify the client network interface's hardware address and the IP address to assign to that client. If the client needs to be able to load a boot file from the server, that file's name must be specified. A simple bootp client declaration might look like this:
host haagen { hardware ethernet 08:00:2b:4c:59:23; fixed-address 239.252.197.9; filename "/tftpboot/haagen.boot"; }
Options
DHCP (and also BOOTP with Vendor Extensions) provide a mechanism whereby the server can provide the client with information about how to configure its network interface (e.g., subnet mask), and also how the client can access various network services (e.g., DNS, IP routers, and so on).
These options can be specified on a per-subnet basis, and, for BOOTP clients, also on a per-client basis. In the event that a BOOTP client declaration specifies options that are also specified in its subnet declaration, the options specified in the client declaration take precedence. A reasonably complete DHCP configuration might look something like this:
subnet 239.252.197.0 netmask 255.255.255.0 { range 239.252.197.10 239.252.197.250; default-lease-time 600 max-lease-time 7200; option subnet-mask 255.255.255.0; option broadcast-address 239.252.197.255; option routers 239.252.197.1; option domain-name-servers 239.252.197.2, 239.252.197.3; option domain-name "isc.org"; }
A BOOTP host on that subnet that needs to be in a different domain and use a different name server might be declared as follows:
host haagen { hardware ethernet 08:00:2b:4c:59:23; fixed-address 239.252.197.9; filename "/tftpboot/haagen.boot"; option domain-name-servers 192.5.5.1; option domain-name "vix.com"; }
A more complete description of the dhcpd.conf file syntax is provided in dhcpd.conf.
OMAPI
The DHCP server provides the capability to modify some of its configuration while it is running, without stopping it, modifying its database files, and restarting it. This capability is currently provided using OMAPI, an API for manipulating remote objects. OMAPI clients connect to the server using TCP/IP, authenticate, and can then examine the server's current status and make changes to it.
Rather than implementing the underlying OMAPI protocol directly, user programs should use the dhcpctl*() API or OMAPI itself. The dhcpctl_*() API is a wrapper that handles some of the housekeeping chores that OMAPI doesn't do automatically. For more information, see dhcpctl*() and OMAPI in the QNX Neutrino C Library Reference.
OMAPI exports objects, which can then be examined and modified. The DHCP server exports the following objects: lease, host, failover-state and group. Each object has a number of methods that are provided: lookup, create, and destroy. In addition, it is possible to look at attributes that are stored on objects, and in some cases to modify those attributes.
The lease object
Leases can't currently be created or destroyed, but they can be looked up to examine and modify their state.
Leases have the following attributes:
The host object
Hosts can be created, destroyed, looked up, examined and modified. If a host declaration is created or deleted using OMAPI, that information will be recorded in the dhcpd.leases file. It's permissible to delete host declarations that are declared in the dhcpd.conf file.
Hosts have the following attributes:
The group object
Named groups can be created, destroyed, looked up, examined and modified. If a group declaration is created or deleted using OMAPI, that information will be recorded in the dhcpd.leases file. It's permissible to delete group declarations that are declared in the dhcpd.conf file.
Named groups currently can only be associated with hosts. This allows one set of statements to be efficiently attached to more than one host declaration.
Groups have the following attributes:
The control object
The control object allows you to shut the server down. If the server is doing failover with another peer, it will make a clean transition into the shutdown state and notify its peer, so that the peer can go into partner down, and then record the "recover" state in the lease file so that when the server is restarted, it will automatically resynchronize with its peer.
On shutdown, the server will also attempt to cleanly shut down all OMAPI connections. If these connections don't go down cleanly after five seconds, they are shut down preemptively. It can take as much as 25 seconds from the beginning of the shutdown process to the time that the server actually exits.
To shut the server down, open its control object and set the state attribute to 2.
The failover-state object
The failover-state object is the object that tracks the state of the failover protocol as it's being managed for a given failover peer. The failover object has the following attributes (see dhcpd.conf for explanations about what these attributes mean):
(Note that some of the above values have changed since DHCP 3.0.x.)
In general, it isn't a good idea to make changes to this state. However, in the case that the failover partner is known to be down, it can be useful to set the DHCP server's failover state to partner down. At this point the DHCP server will take over service of the failover partner's leases as soon as possible, and will give out normal leases, not leases that are restricted by MCLT. If you do put the DHCP server into the partner-down when the other DHCP server isn't in the partner-down state, but isn't reachable, IP address assignment conflicts are possible, even likely. Once a server has been put into partner-down mode, its failover partner must not be brought back online until communication is possible between the two servers.
The dhcpd server depends on the following libraries and binaries:
It also uses the following configuration files:
You should generally create an empty leases file.
dhcpd was originally written by Ted Lemon under a contract with Vixie Labs. Funding for this project was provided by Internet Systems Consortium. Version 3 of the DHCP server was funded by Nominum, Inc. Information about Internet Systems Consortium is available at http://www.isc.org/. Information about Nominum can be found at http://www.nominum.com/.