In this post, I would like to show you how to configure an Ubuntu machine as a DHCP server.

Table of Contents
DHCP, short from Dynamic Host Configuration Protocol, as the name suggests is a Protocol which helps assign IP addresses and other information to hosts from the Local Area Network. DHCP is running on top of the UDP protocol and it is using the well-known ports 67 and 68.
The DHCP server is listening on UDP port 67. The the DHCP clients are listening on UDP port 68.
Server side:

Client side:

DORA is an acronym which helps you remember the messages exchanged between the client and the server.
D – Discover – sent as a broadcast message by the DHCP client looking for a DHCP server

O – Offer – sent by the DHCP server in response to the Discover message. It contains the IP address that the server is offering, the subnet mask, the lease duration, and the IP address of the DHCP server making the offer.

R – Request – sent as a broadcast message by the DHCP client. The client is requesting the offered IP address.

A – Acknowledge – sent by the DHCP server. This packet includes the lease duration and any other configuration information that the client might have requested.

For more information related to DHCP, check this wiki page.
Search for DHCP software
In Ubuntu, if you are looking for a specific software to install and you do not know which package contains it, you can run a command similar to the one below and check for available packets.
petru@petru-ubuntu:~$ apt-cache search dhcp | grep isc-dhcp
isc-dhcp-client - DHCP client for automatically obtaining an IP address
isc-dhcp-common - common manpages relevant to all of the isc-dhcp packages
isc-dhcp-dev - API for accessing and modifying the DHCP server and client state
isc-dhcp-server - ISC DHCP server for automatic IP address assignment
isc-dhcp-client-ddns - Dynamic DNS (DDNS) enabled DHCP client
isc-dhcp-relay - ISC DHCP relay daemon
isc-dhcp-server-ldap - DHCP server that uses LDAP as its backend
python3-isc-dhcp-leases - Python module for reading dhcp leases files (Python 3 interface)
petru@petru-ubuntu:~$

Install DHCP server
As you can see from the above results, there are multiple packages containing the dhcp string. I will install the isc-dhcp-server package.
To install the DHCP server, run the following command.
petru@petru-ubuntu:~$ sudo apt install isc-dhcp-server
[sudo] password for petru:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
isc-dhcp-server-ldap policycoreutils
The following NEW packages will be installed:
isc-dhcp-server
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,244 kB of archives.
After this operation, 4,175 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu lunar/main amd64 isc-dhcp-server amd64 4.4.3-P1-1ubuntu1 [1,244 kB]
Fetched 1,244 kB in 1s (1,009 kB/s)
Preconfiguring packages ...
Selecting previously unselected package isc-dhcp-server.
(Reading database ... 169780 files and directories currently installed.)
Preparing to unpack .../isc-dhcp-server_4.4.3-P1-1ubuntu1_amd64.deb ...
Unpacking isc-dhcp-server (4.4.3-P1-1ubuntu1) ...
Setting up isc-dhcp-server (4.4.3-P1-1ubuntu1) ...
Generating /etc/default/isc-dhcp-server...
Created symlink /etc/systemd/system/multi-user.target.wants/isc-dhcp-server.service → /lib/systemd/system/isc-dhcp-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/isc-dhcp-server6.service → /lib/systemd/system/isc-dhcp-server
6.service.
Processing triggers for man-db (2.11.2-1) ...
petru@petru-ubuntu:~$

Confirm that DHCP is up and running
After the package is installed, you need to check that the DHCP server is up and running.
petru@petru-ubuntu:~$ systemctl status isc-dhcp-server
× isc-dhcp-server.service - ISC DHCP IPv4 server
Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Mon 2023-05-08 16:55:22 BST; 3min 55s ago
Duration: 45ms
Docs: man:dhcpd(8)
Main PID: 6774 (code=exited, status=1/FAILURE)
CPU: 10ms
May 08 16:55:22 petru-ubuntu dhcpd[6774]:
May 08 16:55:22 petru-ubuntu dhcpd[6774]: Not configured to listen on any interfaces!
May 08 16:55:22 petru-ubuntu dhcpd[6774]:
May 08 16:55:22 petru-ubuntu dhcpd[6774]: If you think you have received this message due to a bug rather
May 08 16:55:22 petru-ubuntu dhcpd[6774]: than a configuration issue please read the section on submitting
May 08 16:55:22 petru-ubuntu dhcpd[6774]: bugs on either our web page at www.isc.org or in the README file
May 08 16:55:22 petru-ubuntu dhcpd[6774]: before submitting a bug. These pages explain the proper
May 08 16:55:22 petru-ubuntu dhcpd[6774]: process and the information we find helpful for debugging.
May 08 16:55:22 petru-ubuntu dhcpd[6774]:
May 08 16:55:22 petru-ubuntu dhcpd[6774]: exiting.
petru@petru-ubuntu:~$

In this case, the service has failed. You need to adjust the default configuration. Follow the next step.
Change the default configuration
Next, you will need to change the default configuration. The default configuration is located in the directory /etc/dhcp. The configuration file is named dhcpd.conf. Before editing the dhcpd.conf file, it is wise to create a backup of the original file.
petru@petru-ubuntu:~$ cd /etc/dhcp/
petru@petru-ubuntu:/etc/dhcp$ cp dhcpd.conf dhcpd.conf.default
cp: cannot create regular file 'dhcpd.conf.default': Permission denied
petru@petru-ubuntu:/etc/dhcp$ sudo cp dhcpd.conf dhcpd.conf.default
petru@petru-ubuntu:/etc/dhcp$

Open the file and edit it according to your needs. I added the following configuration in my lab.
petru@petru-ubuntu:/etc/dhcp$ tail -n 15 dhcpd.conf
#
# Config added by Petru
#
option domain-name-servers 8.8.8.8, 1.1.1.1;
option domain-name "gulian.uk.";
subnet 172.16.10.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option broadcast-address 172.16.10.255;
option routers 172.16.10.1;
range 172.16.10.100 172.16.10.125;
}
petru@petru-ubuntu:/etc/dhcp$

Stop and start the DHCP server
After you have modified the configuration of the DHCP server, you need to stop and start the DHCP service. This step is mandatory. Otherwise, the added configuration will not be taken into account.
petru@petru-ubuntu:/etc/dhcp$ sudo systemctl stop isc-dhcp-server
petru@petru-ubuntu:/etc/dhcp$ sudo systemctl start isc-dhcp-server
petru@petru-ubuntu:/etc/dhcp$ sudo systemctl status isc-dhcp-server
● isc-dhcp-server.service - ISC DHCP IPv4 server
Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; preset: enabled)
Active: active (running) since Mon 2023-05-08 17:48:15 BST; 4s ago
Docs: man:dhcpd(8)
Main PID: 7818 (dhcpd)
Tasks: 1 (limit: 4581)
Memory: 3.7M
CPU: 9ms
CGroup: /system.slice/isc-dhcp-server.service
└─7818 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf
May 08 17:48:15 petru-ubuntu sh[7818]: Wrote 0 leases to leases file.
May 08 17:48:15 petru-ubuntu dhcpd[7818]: PID file: /run/dhcp-server/dhcpd.pid
May 08 17:48:15 petru-ubuntu dhcpd[7818]: Wrote 0 leases to leases file.
May 08 17:48:15 petru-ubuntu dhcpd[7818]: Listening on LPF/ens33/00:0c:29:cf:9c:36/172.16.10.0/24
May 08 17:48:15 petru-ubuntu sh[7818]: Listening on LPF/ens33/00:0c:29:cf:9c:36/172.16.10.0/24
May 08 17:48:15 petru-ubuntu sh[7818]: Sending on LPF/ens33/00:0c:29:cf:9c:36/172.16.10.0/24
May 08 17:48:15 petru-ubuntu sh[7818]: Sending on Socket/fallback/fallback-net
May 08 17:48:15 petru-ubuntu dhcpd[7818]: Sending on LPF/ens33/00:0c:29:cf:9c:36/172.16.10.0/24
May 08 17:48:15 petru-ubuntu dhcpd[7818]: Sending on Socket/fallback/fallback-net
May 08 17:48:15 petru-ubuntu dhcpd[7818]: Server starting service.
petru@petru-ubuntu:/etc/dhcp$

Test the DHCP server
It is time to open a client and test if the DHCP server is working as expected.
Cisco Switch used as a client.

Ubuntu laptop used as a DHCP client.

As you can see from the above screenshots both clients received an IP address. The IP address 172.16.10.100 was assigned to the Cisco switch and the IP address 172.16.10.101 was assigned to the Ubuntu laptop.
The same information can be confirmed by checking the logs. By default the DHCP logs are stored in /var/log/syslog file.
petru@petru-ubuntu:/etc/dhcp$ grep 172.16.10.100 /var/log/syslog
2023-05-08T17:53:01.898445+01:00 petru-ubuntu dhcpd[7818]: DHCPOFFER on 172.16.10.100 to 04:fe:7f:87:8e:40 (SW2960) via ens33
2023-05-08T17:53:01.900630+01:00 petru-ubuntu dhcpd[7818]: DHCPREQUEST for 172.16.10.100 (172.16.10.254) from 04:fe:7f:87:8e:40 (SW2960) via ens33
2023-05-08T17:53:01.901586+01:00 petru-ubuntu dhcpd[7818]: DHCPACK on 172.16.10.100 to 04:fe:7f:87:8e:40 (SW2960) via ens33
2023-05-08T17:58:07.999747+01:00 petru-ubuntu dhcpd[7818]: DHCPREQUEST for 172.16.10.100 from 04:fe:7f:87:8e:40 (SW2960) via ens33
2023-05-08T17:58:08.000305+01:00 petru-ubuntu dhcpd[7818]: DHCPACK on 172.16.10.100 to 04:fe:7f:87:8e:40 (SW2960) via ens33
2023-05-08T18:03:11.013230+01:00 petru-ubuntu dhcpd[7818]: DHCPREQUEST for 172.16.10.100 from 04:fe:7f:87:8e:40 (SW2960) via ens33
2023-05-08T18:03:11.014514+01:00 petru-ubuntu dhcpd[7818]: DHCPACK on 172.16.10.100 to 04:fe:7f:87:8e:40 (SW2960) via ens33
2023-05-08T18:08:14.063146+01:00 petru-ubuntu dhcpd[7818]: DHCPREQUEST for 172.16.10.100 from 04:fe:7f:87:8e:40 (SW2960) via ens33
2023-05-08T18:08:14.063981+01:00 petru-ubuntu dhcpd[7818]: DHCPACK on 172.16.10.100 to 04:fe:7f:87:8e:40 (SW2960) via ens33
petru@petru-ubuntu:/etc/dhcp$

For a complete view, you can inspect the file /var/lib/dhcp/dhcpd.leases.
petru@petru-ubuntu:/etc/dhcp$ tail -n 11 /var/lib/dhcp/dhcpd.leases
lease 172.16.10.100 {
starts 1 2023/05/08 17:08:14;
ends 1 2023/05/08 17:18:14;
cltt 1 2023/05/08 17:08:14;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 04:fe:7f:87:8e:40;
uid "\000cisco-04fe.7f87.8e40-Vl1";
client-hostname "SW2960";
}
petru@petru-ubuntu:/etc/dhcp$

It seems that everything is working as it should. By following these instructions, you have installed DHCP server on a Ubuntu machine and confirmed that it allocates IP addresses to DHCP clients.
If you want to configure DHCP server on a Cisco router, take a look at this post: How to configure a DHCP server on a Cisco router .
I hope you find this post useful. Share it on your social media channels so that other people can read it too.