[OpenBSDsupport]

Using OpenBSD as a DHCP Server


Being well suited for all applications as a network service host, it is no surprise that OpenBSD works well as a DHCP server. It ships stock with the ISC dhcpd. Configuration and management of the daemon are easy and well documented.


1.0 - Introduction

Let me first begin by stating that if you have read the OpenBSD FAQ, you don't have to read this HOWTO. The FAQ gives enough information to set up your server to serve DHCP requests from your network and it has been used as the basis for this HOWTO. For further documentation, see the following man pages: dhcpd(8), dhcpd.conf(5), and dhcp-options(5)

2.0 - Preliminaries (rc.conf, dhcpd.interfaces)

There are only a handful of files that need to be configured for dhcpd. The first thing to do is enable it at startup. Like most daemons, this can be done by editing the /etc/rc.conf. There will be a line labeled "dhcpd_flags". Set this argument to include the option "", as shown here:

dhcpd_flags=""        # for normal use: ""

This will enable the DHCP server at boot; the /etc/rc file will make sure this option is not disabled and start it for any interfaces you have defined. This brings us to the second step; decide which network interface(s) that dhcpd will listen for requests from, and enable that in the file /etc/dhcpd.interfaces:

#       $OpenBSD: dhcpd.interfaces,v 1.1 1998/08/19 04:25:45 form Exp $
#
# List of network interfaces served by dhcpd(8).
#
# ep0
# ed0 le0
# de1
fxp1

In the above example, all lines are commented out, except for the interface name fxp1. In this example, this host is running a firewall with two interfaces. fxp1 is the interface connected to the LAN, where clients' DHCP requests will originate from. If you have more than one interface you with your server to serve requests from/listen to, place the interface name in this file. If you do not specify an interface, dhcpd will try and listen on all interfaces with a broadcast address.

dhcpd can server DHCP requests on multiple interfaces as shown here:

#       $OpenBSD: dhcpd.interfaces,v 1.1 1998/08/19 04:25:45 form Exp $
# List of network interfaces served by dhcpd(8).
ath0
sis0 sis1

3.0 - Edit /etc/dhcpd.conf

The main configuration file for dhcpd is /etc/dhcpd.conf. This file contains all of the client options, subnet definitions, and other options dhcpd recognizes. The dhcpd.conf(5) man page describes the what the various options mean. A sample configuration file is given below, and followed by an explanation of the various options.

A sample configuration file is given below, and followed by an explanation of the various options.

#       $OpenBSD: dhcpd.conf,v 1.1 1998/08/19 04:25:45 form Exp $
#
# DHCP server options.
# See dhcpd.conf(5) and dhcpd(8) for more information.
#

# Network:              10.0.0.0/255.255.255.0
# Domain name:          mydomain.tld
# Name servers:         10.0.0.2 and 10.0.0.3
# Default router:       10.0.0.1
# Addresses:            10.0.0.20 - 10.0.0.250
#

############################
# this is to specify to the dhcpd server that 
# some of the subnets share the same network information
############################
shared-network MYDOMAIN-TLD {

        ############################
        # The three lines below are to specify the shared resources
        #  for all the subnets specified below
        #
        # order of options
        # Lease duration: one week (7 days)
        # domain name for DNS and such
        # DNS servers to use for lookups
        ############################
        default-lease-time 604800;
        option  domain-name "mydomain.tld";
        option  domain-name-servers 10.0.0.2, 10.0.0.3;

        ############################
        # Specify the subnet to give ips on and the netmask
        #  given with the ip address
        ############################
        subnet 10.0.0.0 netmask 255.255.255.0 {
                #specify the subnet again (see below NB***)
                option subnet-mask 255.255.255.0;
                #specify the broadcast address for the subnet
                option broadcast-address 10.0.0.255;
                #specify the gateway to use
                option routers 10.0.0.1;

                #specify the range of IPaddresses to lease
                range 10.0.0.20 10.0.0.250;
        }
}

Note that the general syntax of the file is to include everything in braces, and ending the configuration lines in semicolons. This is important.

NB***: Although a netmask must be given with every subnet declaration, it is recommended that if there is any variance in subnet masks at a site, a subnet-mask option statement be used in each subnet declaration to set the desired subnet mask, since any subnet-mask option statement will override the subnet mask declared in the subnet statement.

The first section of commented lines at the top are a good way to figure out a configuration. Decide which networks you will provide configuration for, and define them by subnet and netmask. Generally the domain name and name servers will be global for the organization, and the options such as the netmask, broadcast address, and default gateway (labeled router) are specific to the particular subnet. Under each subnet declaration, a range of addresses is given that will be leased to clients.

4.0 - Start dhcpd

With the dhcpd.conf file edited and set up for your configuration, you can now start dhcpd and it will serve requests. To do so, you can either reboot the system (at which point the system rc scripts will launch it with the correct options), or you can start it manually.

If dhcpd is started manually, it will require that a file exist for it to store it's lease database in. This file defaults to /var/db/dhcpd.leases and will not be created automatically. First, create this file, and then start dhcpd with the -q argument and the name of the interface(s) it will listen on (which you would have determined above). When the system starts the dhcpd server via the rc scripts, the /etc/dhcpd.interfaces file is parsed and the dhcpd server is set to listen on the specified interfaces (or all interfaces if none are specified).

touch /var/db/dhcpd.leases
dhcpd -q fxp1

Take a look at /var/log/messages to make sure that there were no errors in your configuration or startup. You can also look at the output of ps to make sure that it is running:

ps ax | grep dhcpd

USER       PID %CPU %MEM   VSZ   RSS TT   STAT STARTED       TIME COMMAND

_dhcp    11760  0.0  0.1   588   568 ??  Ss    10:27PM    0:00.04 dhcpd fxp1

Should you need to make changes to the configuration of your DHCP server, you will have to stop and restart the server manually. To do so, kill the dhcpd PID and restart manually.

5.0 - Conclusion

Complex configurations in dhcpd are possible, such as lease reservations for static hosts and more. See the relevant man pages for details. This HOWTO should give you a basic configuration that will be well-suited for serving DHCP request on a small home or office network.

If you found this HOWTO useful or would like to suggest improvements, please let me know.


Submitted by: [ sancho <at> sancho2k <dot>net ]

Updated to 4.2 and modified by Fred Crowson.

Revised for 3.8 by: [mdcalvi <at> cox <dot>net ]