DHCP Overview

DHCP Client Setup

DHCP Server Setup

DHCP Overview

Introduction and Purpose

This document attempts to explain how to setup DHCP clients and servers for the NetBSD operating system.

What is DHCP?

DHCP stands for Dynamic Host Configuration Protocol. It allows dynamic configuration of the network configuration of a host computer. The basic idea is this: When a DHCP client is turned on, it initially doesn't have an IP address assigned to it. It issues a broadcast message to any DHCP servers which are on the network. An exchange takes place during which the DHCP server assigns an IP address to the client and tells the client certain key network configuration parameters (such as name server addresses for example).

Who needs to use DHCP?

Many internet service providers (ISPs) require that their customers use a DHCP client so the ISP may dynamically assign IP addresses and control other network settings. Another use is for laptop computers which may be connected to more than one network. For example a laptop may be connected to a network in the office and also at home. This is an ideal use for DHCP as the laptop doesn't need to be manually reconfigured for use in the 2 different networks. In this case there needs to be a DHCP server both on the office network and the home network and the laptop needs a DHCP client.

Sources of More Detailed Information

For more information about DHCP in general, please refer to RFC 1541, Request for Comments document for the Dynamic Host Configuration Protocol (DHCP). In addition there is a comprehensive DHCP FAQ.

DHCP Client Setup

Configure DHCP

The DHCP client can be configured in the file /etc/dhcpcd.conf. If the file is not present, DHCP will still work fine. See dhcpcd.conf(5) and dhcpcd-run-hooks(8) for more detailed information.

Enable DHCP

Edit /etc/rc.conf and edit the 'dhcpcd' line to read 'dhcpcd=YES'. By default, DHCP requests will be sent to all attached network interfaces. If you want to only use DHCP on a single/less network cards, add a list of network interfaces which should be configured with DHCP to the 'dhcpcd_flags' line. For example, 'dhcpcd_flags="wm0"'.

The next time you reboot your machine it will configure itself as a DHCP client. To enable DHCP without rebooting, run the command 'service dhcpcd start'.

How do I keep dhcpcd from nuking my /etc/resolv.conf?

Usually dhcpcd should rewrite your /etc/resolv.conf with information it retrieved from the DHCP server. In the rare occasions that this is not desired, you can add dhcpcd_flags="-C resolv.conf" to /etc/rc.conf.

DHCP Server Setup


This section shows how to setup a DHCP server. Note that you do not need to set up a DHCP server unless you want to dynamically assign addresses for computers on your LAN. For more detailed information see dhcpd(8), dhcpd.conf(5), and dhcp-options(5).

Configure DHCPD

The DHCP server configuration is contained in the file /etc/dhcpd.conf. If this file does not exist on your system, you will have to create it. Remember to customize this as needed, ie: change the hostname stuff and the ethernet interface. A typical /etc/dhcpd.conf is shown below. In the example, 7 addresses are made available for use by DHCP clients. These addresses are through The DHCP server will tell the clients what IP address, netmask, routers, name servers, and domain name to use.

# Setting DHCPD global parameters
allow unknown-clients;

# Set parameters for the subnet.
subnet netmask {
range;                <=== Range of IP addresses
                                                   available for assignment.
default-lease-time 604800;                    <=== Default lease time in 
                                                   seconds.  This is the time
                                                   assigned if the client doesn't
                                                   request one.
max-lease-time 604800;                        <=== Maximum time a lease will be 
option subnet-mask;             <=== subnetmask given to clients
option domain-name-servers,;  <=== put a list of name server IP
                                                   addresses here.
option domain-name "";
option routers;                   <=== list of routers the clients should

Enable DHCPD

Edit /etc/rc.conf and edit the 'dhcpd' line to read 'dhcpd=YES'. If you don't want to serve DHCP requests on all network interfaces, add a list of network interfaces on which DHCPD should run to the 'dhcpd_flags' line. For example, 'dhcpd_flags="-q ae1"'.

Create a dhcpd.leases file

dhcpd wants a /var/db/dhcpd.leases file to exist. Create it by running 'touch /var/db/dhcpd.leases'.

Back to Networking documentation