• We had to restore from a backup today after a failed software update. Backup was from 0000 EDT and restored it at 0800 EDT so we lost about 8hrs. Today is 07/20/2024. More info here.

LFCS – Setting up a DHCP Server

Jarret B

Well-Known Member
Staff member
May 22, 2017
Reaction score
Most people may not deal directly with a Dynamic Host Control Protocol (DHCP) Server. Everyone will connect to the internet at times and their device is assigned an IP Address. A DHCP Server assigns the IP Addresses to devices connecting to the specific network.

We are going to set up a DHCP Server on Server 1, and Server 2 will be get assigned its IP Address from Server 1.

From a DHCP Server, we can assign an IP Address, Subnet Mask, Gateway, DNS Server, etc. to the devices connecting to that network. The network can be a wired or wireless network.

Disable DHCP on VirtualBox

For those of you using VirtualBox to emulate your servers, you will need to stop the DHCP Service on VirtualBox so we can use our own server to manage the service.

These steps are the same for Both Ubuntu and CentOS.

For newer versions of VirtualBox, select 'File', 'Tools' and then 'Network Manager' to open the manager you need to set up a new Network Adapter for use by Virtual Machines.

In the new window that opened, select the 'Host-Only Networks' tab. Then select the 'Create' icon to create a new Host-Only Adapter.

My new adapter is called 'VirtualBox Host-Only Ethernet Adapter #3'. At the bottom of the screen should be a listing of the IP Addresses that are assigned by the DHCP Server for this adapter. Click on the tab for 'DHCP Server' and make sure the checkbox for 'Enable Server' is unchecked.

Open the 'Settings' for Server1 and go to the 'Network' settings. Find the Adapter that is listed as a 'Host-Only Adapter'. For the 'Name', drop-down the list and select the adapter you created previously. In my case, it is 'VirtualBox Host-Only Ethernet Adapter #3'. Do this for all your Servers you are using for these LFCS articles.

Static Address on Server1

A DHCP Server must keep the IP Address. Since the DHCP Server is assigning addresses, the clients need to know the IP Address of the server to renew the IP Address Lease. To renew the address, it must contact the DHCP Server. If the DHCP Server IP Address has changed, it cannot contact the DHCP Server for address renewal.

NOTE: The connection for 'enp0s8' most likely will fail at startup since it cannot find a DHCP Server. Disregard this since we are setting it up as static.

If you are performing this on VirtualBox, start up Server1. When the system starts, open a terminal. Perform the command 'ip a' and you should see that the adapter named 'enp0s8' does not have an IP Address assigned to it since we removed its DHCP Server.

Now, we need to assign a static IP Address to the adapter.

The following is for a CentOS system to assign a static IP Address.

You'll need to edit the file '/etc/sysconfig/network-scripts/ifcfg-enp0s8' with ROOT privileges. The contents should be something like:

ETHTOOL_OPTS="autoneg on"

Change the line BOOTPROTO=dhcp to BOOTPROTO=none and PEERDNS=yes to PEERDNS=no. If the PEERDNS line is not present, then add the line below. Add the lines:


Save the changes and reboot the system. Once it has restarted, open a terminal and run 'ip a' to verify that the 'enp0s8' adapter has the new address. If you use my example exactly, the address should be ''. If you changed it, then verify that it is the address that you set.

For an Ubuntu system, do the following steps.

Edit the file /etc/netplan/01-netcfg.yaml with ROOT privileges and add the following into it:
version: 2
renderer: networkd
dhcp4: no
dhcp6: no
addresses: [, ]
addresses: []

Save the file and exit your editor. Run the command sudo netplan apply for the changes to take effect. Run ip a to verify that the IP Address is now

NOTE: If any errors occur, verify the configuration file is correct and also that no other running virtual machine has the same IP Address. If needed, choose a different IP Address as the static address.

Install and Configure DHCP

The first part of this section will cover CentOS.

To install DHCP on CentOS, use the command:

sudo yum install dhcp -y

DHCP is installed, and now we need to configure it to work on our network.

There is an example file called '/usr/share/doc/dhcp*/dhcpd.conf.example' if you want to look at one, but we'll create our own at /etc/dhcp/dhcpd.conf. The file exists, but is empty except for comments. Open the file with your editor and add:

option domain-name-servers;
option domain-search "example.com";
default-lease-time 43200;
max-lease-time 43200;
subnet netmask {
host server2 {
hardware ethernet 08:00:27:30:bc:24;

The first line designates the IP Addresses of the DHCP Servers. In this case, there is only one. The 'domain-search' is 'example.com' which is the domain name I set on my systems. So, Server1 is server1.example.com which is the Fully Qualified Domain Name (FQDN).

We set the DHCP Server as 'authoritative' to show it is the main DHCP Server. If a group of DHCP Servers exists, then only one is authoritative.

The default lease time is a number in seconds that tells how long the lease for the IP Address is valid. After half the lease time has expired, the system will attempt to negotiate a new lease expiration. The max lease time is how long a system can have a lease on an IP Address before it must get a new lease. In the case above, 43200 is 12 hours. In most cases, in a business, a workday is 9 hours (1 for lunch), so the lease should expire every day after work.

NOTE: We should set all servers to have a static IP Address.

Next, we set the network subnet and subnet mask. A subset of this is to specify the range of IP Addresses that the DHCP Server can lease out to devices. So our server will give out addresses from to

The last section is setting up a static IP Address for Server2. The first line lists the MAC Address of the NIC on Server2 (in this case, enp0s8). To get the MAC Address, run 'ip a' and find the MAC for the adapter in the list.

Save the file and you are ready to start the service:

sudo systemctl enable dhcpd
sudo systemctl start dhcpd

Everything is ready now for using DHCP on the network.

Now we can set up DHCP on an Ubuntu Server.

To install DHCP, use the command:

sudo apt install isc-dhcp-server -y

To configure the DHCP Server, you need to edit the file /etc/dhcp/dhcpd.conf. You cen comment or remove the existing lines and add:

subnet netmask {
 option domain-name-servers server1.example.com;
 option domain-name "example.org";
 option subnet-mask;
 default-lease-time 43200;
 max-lease-time 43200;
host server2 {
hardware ethernet 08:00:27:50:f1:f4;

Instead of setting the options globally, like with CentOS, I am setting the options specifically for the designated subnet. If multiple subnets are being issued, then we can set the values for each subnet specifically and not globally.

We need to bind the DHCP Server to the required Adapter in the file /etc/default/isc-dhcp-server. Change the line INTERFACESv4=""' to INTERFACESv4="enp0s8". The DHCP Server is now bound to the adapter at enp0s8 for IPv4. You can bind to multiple adapters by separating them with spaces.

To start the service, use the commands:

sudo systemctl enable isc-dhcp-server
sudo systemctl start isc-dhcp-server

Now the DHCP Service is running on Ubuntu.

Testing DHCP

Start Server2 and check the IP Address, with ip a for the enp0s8 adapter. If the IP Address is not, then disconnect the adapter and reconnect it. You can perform a disconnection and re-connection with the command 'sudo netplan apply'.

In the output for ip a you can see the lease time shown in seconds after the label valid_lft.


Setting up a DHCP Server is a basic necessity for a network that doesn't have a router or some such device to act as a DHCP Server.

Most businesses may require a DHCP Server to issue addresses to client systems.

Keep in mind how to set up a DHCP Server not just for the LFCS Exam, but real-life practices.
Last edited by a moderator:

Members online

Latest posts