Applies to Ubuntu 14.xx-18.xx
Configure DHCP Server in Ubuntu

We’re going to assume that you have already updated your server, setup a Static IP Address on your machine and that it is connected to a network ready to lease to internal hosts. If you have not done so, please do so before continuing this guide.

1. Install the isc-dhcp-server from the repository.

sudo apt install isc-dhcp-server -y

2. We’re going to make a backup of our original configuration /etc/dhcp/dhcpd.conf and use it as a template to configure our own DHCP server.

sudo mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak

3. Lets create a new configuration file with the same name as the original using your preferred text editor, i will be using VIM.

sudo vim /etc/dhcp/dhcpd.conf

And lets take a quick look at one of the examples listed in the original config file.

# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {
# range 10.5.5.26 10.5.5.30;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
# default-lease-time 600;
# max-lease-time 7200;
#}

We can adopt this configuration so it matches what we want to use. The subnet that i have configured on my interface is 20.20.20.0/24 so i will create my subnet in accordance to that.

subnet 20.20.20.0 netmask 255.255.255.0 {
 range 20.20.20.50 20.20.20.100;
 option domain-name-servers 1.1.1.1;
 option routers 20.20.20.254;
 option broadcast-address 20.20.20.255;
 default-lease-time 1500;
 max-lease-time 1500;
}

As you can tell, i removed some unnecessary configurations from the original examples as i don’t really need them but you can use them if you’d like.

NOTE: When setting the range, if you are planning on having several static devices on your network it is good to keep the range smaller than the entire subnet that way you have some free space for static addressing and not have to worry about creating reservations. Sometimes this may not be all that necessary if its only a handfull of devices that need static, in that case a range for the entire subnet should be fine but always exclude your gateway from the range.

4. Once we have our configuration set to what we want it to, lets restart the isc-dhcp-server.service.

sudo systemctl restart isc-dhcpd-server.service

5. Verify that your devices are getting a lease and we can check the active leases located in /var/lib/dhcp/dhcpd.leases.

cat /var/lib/dhcp/dhcpd.leases

# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.3.5
# authoring-byte-order entry is generated, DO NOT DELETE
authoring-byte-order little-endian;

lease 20.20.20.50 {
 starts 1 2018/09/03 18:10:49;
 ends 1 2018/09/03 18:35:49;
 tstp 1 2018/09/03 18:35:49;
 cltt 1 2018/09/03 18:10:49;
 binding state active;
 next binding state free;
 rewind binding state free;
 hardware ethernet 58:ef:68:e5:6b:99;
 uid "\001X\357h\345k\231";
 set vendor-class-identifier = "dhcpcd-6.8.2:Linux-4.4.141-14522-g0cbf5e09ecee:x86_64:GenuineIntel";
}
lease 20.20.20.51 {
 starts 1 2018/09/03 18:11:33;
 ends 1 2018/09/03 18:36:33;
 tstp 1 2018/09/03 18:36:33;
 cltt 1 2018/09/03 18:11:33;
 binding state active;
 next binding state free;
 rewind binding state free;
 hardware ethernet 00:05:1b:a4:96:9d;
 uid "\001\000\005\033\244\226\235";
 set vendor-class-identifier = "MSFT 5.0"; client-hostname "LINUXMAN-PC";
}
server-duid "\000\001\000\001# 5\033\010\000'\224\006\262";

I have both my Chromebook and Windows PC getting a DHCP lease from our newly configured DHCP Server.I have both my Chromebook and Windows PC getting a DHCP lease from our newly configured DHCP Server.