DHCP

Dynamic Host Configuration Protocol #

The Dynamic Host Configuration Protocol (DHCP) is a way to configure network interfaces automatically. OpenBSD can be a DHCP server that configures other machines, or a DHCP client that is configured by a DHCP server.

DHCP Server #

First we need to create a valid configuration for the dhcp server. As usual with Base services, there’s an example file in /etc/examples/dhcpd.conf. Copy the example file to /etc cp /etc/examples/dhcpd.conf /etc/.

The example file looks like the following:

#	$OpenBSD: dhcpd.conf,v 1.1 2014/07/11 21:20:10 deraadt Exp $
#
# DHCP server options.
# See dhcpd.conf(5) and dhcpd(8) for more information.
#

# Network:		192.168.1.0/255.255.255.0
# Domain name:		my.domain
# Name servers:		192.168.1.3 and 192.168.1.5
# Default router:	192.168.1.1
# Addresses:		192.168.1.32 - 192.168.1.127
#
option  domain-name "my.domain";
option  domain-name-servers 192.168.1.3, 192.168.1.5;

subnet 192.168.1.0 netmask 255.255.255.0 {
	option routers 192.168.1.1;

	range 192.168.1.32 192.168.1.127;

	host static-client {
		hardware ethernet 22:33:44:55:66:77;
		fixed-address 192.168.1.200;
	}

	host pxe-client {
		hardware ethernet 02:03:04:05:06:07;
		filename "pxeboot";
		next-server 192.168.1.1;
	}
}

This file assumes the ip address of the router, or gateway, to be 192.168.1.1. Change it to the actual ip address of your router/gateway. Also, it assumes that the DNS servers on your local network to be found on 192.158.1.3 and 192.168.1.5. Change the ip addresses on the “option domain-name-servers 192.168.1.3, 192.168.1.5;” line to whatever name servers you wish to use. They can also be external ip addresses like Google’s 8.8.8.8 and 8.8.4.4, or Cloudflare’s 1.1.1.1.

It’s possible to use the DHCP server to assign the same ip address to the same MAC address everytime a DHCP request is being made. This can be useful for servers like a fileserver, ftp-server, or web server, on your local network. If you don’t plan on using this feature, it’s safe to remove the entries from the configuration file. If you would like to use the feature, look up the MAC address, or hardware address of the server/machine you wish to assign the “static” ip address to.

Once the configuration file contains the correct values, it’s time to start the server.

rcctl start dhcpd

In order to start the DHCP server next time the server is started, use the following command

rcctl enable dhcpd

By default, the OpenBSD DHCP server will listen on all network interfaces for DHCP requests. If you run the service on a router/gateway, it’s important to make sure it only listens on the local/internal network interface. Use the following command to make the DHCP service listen only on one interface. In this case the interface is re1. Use the ifconfig command to find out the interface name of your local network.

rcctl set dhcpd flags re1