Synopsis #
Dynamic Host Configuration Protocol (DHCP) allows systems on a network to automatically obtain IPv4 addresses and associated configuration information such as DNS resolvers and default gateways. OpenBSD provides native support for both DHCP clients and servers for IPv4. For IPv6 address configuration, OpenBSD uses SLAAC (Stateless Address Autoconfiguration) with slaacd(8) rather than DHCPv6.
This chapter describes how to configure both the DHCP client and server for IPv4 in OpenBSD, including interface configuration, lease management, and optional settings. For IPv6 autoconfiguration and router advertisement, refer to the SLAAC chapter.
Overview of IP Configuration Tools #
The following table provides a comparison of tools available in the OpenBSD base system and ports for managing IP address configuration for both IPv4 and IPv6:
| Utility | Description | IPv4 | IPv6 |
|---|---|---|---|
dhcpleased(8) | DHCP client | ✔ | ✖ (use slaacd) |
dhcpd(8) | DHCP server | ✔ | ✖ |
dhcpleased.conf(5) | DHCP client configuration file | ✔ | ✖ |
slaacd(8) | SLAAC client | ✖ | ✔ |
rad(8) | Router Advertisement daemon | ✖ | ✔ |
dhcp6s (ports) | DHCPv6 server (via ports) | ✖ | ✔ |
dhcp6c (ports) | DHCPv6 client (via ports) | ✖ | ✔ |
For IPv6 support, OpenBSD prefers SLAAC over DHCPv6. The base system includes all necessary tools for SLAAC and includes dhcp6leased(8) for DHCPv6 prefix delegation; it does not provide a base DHCPv6 server or general stateful host-address client. See the SLAAC and IPv6 Autoconfiguration
chapter for detailed guidance.
Configuring the DHCP Client #
The default-enabled dhcpleased(8)
daemon configures interfaces marked inet autoconf.
Interface Setup #
Add this line to /etc/hostname.em0, retaining required link or wireless settings:
inet autoconf
Apply it with:
doas sh /etc/netstart em0
The legacy dhcp spelling remains an alias, but it no longer starts dhclient.
Inspect and Renew Leases #
Inspect the active lease through the daemon’s control utility:
dhcpleasectl -l em0
Request a new lease with:
doas dhcpleasectl em0
Do not use the removed dhclient -r command. To stop automatic IPv4 configuration, set inet -autoconf in the interface file and apply doas ifconfig em0 inet -autoconf; plan address and route changes from a console.
Hostname Configuration #
To suppress the hostname option, use /etc/dhcpleased.conf:
interface em0 {
send no host name
}
DHCP Client Customization #
Use dhcpleased.conf(5)
for supported per-interface options. Legacy dhclient.conf syntax is not accepted.
Example Configuration #
To ignore DNS proposals from this interface:
interface em0 {
ignore dns
}
Put the required search and nameserver lines in /etc/resolv.conf. resolvd(8) keeps these lines while adding DNS settings from other interfaces. Check the configuration, then restart dhcpleased to apply it; this service does not support reload:
doas dhcpleased -n && doas rcctl restart dhcpleased
Configuring the DHCP Server #
OpenBSD includes its maintained ISC-derived server as dhcpd(8), which provides dynamic address assignment for clients on a local network.
Example dhcpd.conf #
For a basic DHCP subnet, use:
option domain-name "example.net";
option domain-name-servers 192.0.2.53;
subnet 192.0.2.0 netmask 255.255.255.0 {
range 192.0.2.100 192.0.2.200;
option routers 192.0.2.1;
}
Save this configuration as /etc/dhcpd.conf.
Starting and Enabling the DHCP Server #
To enable and start the DHCP server on a specific interface (e.g., em1):
doas rcctl enable dhcpd
doas rcctl set dhcpd flags em1
doas rcctl start dhcpd
Specify the intended LAN interfaces explicitly; without operands, the daemon can discover and listen on multiple broadcast interfaces. Validate /etc/dhcpd.conf with doas dhcpd -n before starting it.
Logging and Troubleshooting #
DHCP client and server logs are written to /var/log/daemon. To observe real-time DHCP activity:
doas tail -f /var/log/daemon
Ensure no other DHCP server is running on the same network segment. Packet filtering rules must also allow DHCP traffic (UDP ports 67 and 68).
Stop the existing server instance before foreground diagnostics. Then start dhcpd in the foreground with verbose output:
doas dhcpd -dv em1