Setting up the DHCP server

  • by Patrick Ogenstad
  • April 25, 2018

We will be using ISC DHCP as our server, while this guide describe the steps using Ubuntu 16.04 it should be similar enough on another Linux distribution.

Installing ISC DHCP

apt-get update
apt-get install isc-dhcp-server

On our system the main configuration file for the DHCP server will be /etc/dhcp/dhcpd.conf. A lot of the DHCP options we need are already predefined within the DHCP server and should be available in the sample configuration file. These include options such as subnet-mask and routers (for default gateway). We have to let our clients know where the TFTP server is located, this is done using option 150 which isn’t predefined in the server.

option ip-tftp-server code 150 = { ip-address };

After that we can start out with this configuration, just make sure that you swap out the ip addresses to match your environment.

ddns-update-style none;
option ip-tftp-server code 150 = { ip-address };

default-lease-time 86400;
max-lease-time 86400;

subnet 172.29.50.0 netmask 255.255.255.224 {
  range 172.29.50.18 172.29.50.24;
  option domain-name-servers 172.29.50.34, 172.29.52.37;
  option domain-name "int.networklore.com";
  option subnet-mask 255.255.255.224;
  option routers 172.29.50.1;
  option ip-tftp-server 172.29.50.12;
  default-lease-time 600;
  max-lease-time 7200;
}

Once the config file is edited you need to restart the server.

sudo service isc-dhcp-server restart

If you’re just doing a simple lab it’s could be ok to edit these files manually, but even in my home network I’m using jinja to generate the configuration and I’m pushing out the changes with Ansible. Even if you only have one subnet in the dhcp configuration I would still strongly recommend a configuration management tool.

Is this DHCP server really needed?

The short answer is no. DHCP is required though but you could use any server. Even a Cisco switch will do. Later on we will look at assigning configuration files dynamically from the DHCP server which can’t in a reasonable way be done on an IOS device. However, this dynamic way is optional and you have to decide what suites your needs. The examples shown in the main guide will be using ISC DHCP though. Yet as stated it’s perfectly fine to start out with a network device with a configuration like this:

ip dhcp pool ZTP
 network 172.29.50.0 255.255.255.224
 default-router 172.29.50.1
 option 150 ip 172.29.50.12
!

Completing this step

Make sure you have a working DHCP server and that clients can get an ip address. If your DHCP server isn’t located in the same subnet as your network devices you will need to setup an ip helper.