OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • Overview of IP Configuration Tools
        • Configuring the DHCP Client
          • Interface Setup
          • Inspect and Renew Leases
          • Hostname Configuration
        • DHCP Client Customization
          • Example Configuration
        • Configuring the DHCP Server
          • Example dhcpd.conf
          • Starting and Enabling the DHCP Server
        • Logging and Troubleshooting

        DHCP on OpenBSD

        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:

        UtilityDescriptionIPv4IPv6
        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
        
        Report a bug
        • Synopsis
        • Overview of IP Configuration Tools
        • Configuring the DHCP Client
          • Interface Setup
          • Inspect and Renew Leases
          • Hostname Configuration
        • DHCP Client Customization
          • Example Configuration
        • Configuring the DHCP Server
          • Example dhcpd.conf
          • Starting and Enabling the DHCP Server
        • Logging and Troubleshooting