Configure DHCP
server in ubuntu

Applies to Ubuntu 14.xx-18.xx

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 netmask {
# range;
# option domain-name-servers;
# option domain-name "";
# option routers;
# option broadcast-address;
# 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 so i will create my subnet in accordance to that.

subnet netmask {
 option domain-name-servers;
 option routers;
 option broadcast-address;
 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 {
 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 {
 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.

If you are interested in learning more about Linux, i highly recommend this book on Linux Administration