Linux Commands

How to Install and Configure DHCP on Linux

Any system or network administrator working in large, busy computing environments will often find it hectic to set up new clients and assign them IP addresses and an array of other configuration parameters. This is where DHCP or Dynamic Host Configuration Protocol comes in handy.

DHCP or Dynamic Host Configuration Protocol is a client-server protocol that automatically and dynamically assigns IP addresses and other configuration parameters to devices within your network.

This tutorial explains how to configure a DHCP server and set it up for your network. This guide will also illustrate how to configure the DHCP client system. Note that this guide is specific to Ubuntu 20:04 and not on any other operating systems.

Introduction to DHCP and DHCP Allocation Methods

While our previous article introduced DHCP and elaborately discussed how it works, it is still vital to introduce it here and explain the various allocation options you can use.

The operational mechanism of DHCP is pretty simple. Many computers do not have IP addresses when they boot up—unless they have a dedicated static IP address.

After booting, a machine will use the automatic DHCP Discover component to send a broadcast. The DHCP server will respond to the request or broadcast and contact the client using the DHCP Offer unicast traffic. The DHCP Offer traffic carries the designated IP Address assigned to the client. It also contains the server’s DNS IP address and the Default IP Address for the Gateway.

The client will consequently send a DHCP Request to the server acknowledging receipt and acceptance of the configuration parameters. The servers will keep records of all assigned addresses to prevent IP address collisions or double assignments. For local networks, there must only be a single server.

The following are the critical allocation methods.

  • Manual Allocation– you will base your distribution of IP addresses on MAC (Media Access Control) Addresses. This allocation system gives each machine a fixed IP address and the DHCP server will consistently send the device a fixed configuration based on its MAC Address.
  • Automatic Allocation– The server will use a first come, first serve method to assign IP addresses automatically and dynamically. The addresses assigned can either have Fixed Lease Time or Infinite Lease Time. IP addresses with fixed lease time will expire after some time. On the other hand, IP addresses with infinite lease time will stay permanently for the client.

Step-By-Step Guide on How to Configure DHCP Server on Ubuntu

You need to follow these steps to configure a DHCP server to your Linux system:

Step 1: Ensure that Your Systems Meet All the Specifications

First off, ensure that your system meets all the necessary prerequisites. They include:

  • You have two computer systems, both running Ubuntu 20:04
  • Privilege to access your network as a root user with the ability to use the sudo command

Step 2: Install DHCP Server

On your designated DHCP server machine, install the DHCP server. Notably, the DHCP server package comes in the Ubuntu default depository. You will use the following command to implement the installation:

Step 3: Start Your DHCP Service

Start your DHCP service to enable it to start at system reboot. You can accomplish this using the following commands:

Step 4: Configure the DHCP Service

The DHCP configuration file is available at /etc/default/isc-dhcp-server. You can edit the file with the correct details to specify your network interface. The below command will help you achieve this:

You can specify your network using this command:

Proceed to save and close the file once finished. The next step is to edit the configuration (/etc/dhcp/dhcpd.conf) file to define your DHCP lease. The below command should be used:

Uncomment the below line:

The final step when configuring your server is to change the lines below appropriately:

Save and close this file once you finish editing everything.

Step 5: Configure the DHCP Server for Static IP Address Assignment to Clients

The DHCP server has a default configuration to assign dynamic IP addresses to clients within the network. However, you need to configure your server to give static IP addresses to DHCP clients based on each client’s MAC address.

For instance, we can assign to a client with the 4c:bb:58:9c:f5:55 MAC address. Edit your /etc/dhcp/dhcpd.conf file using the nano command as shown below to achieve this.

You should add the following lines to the file:

Save the changes and close the file.

It is time to restart your DHCP service to implement the changes. You can use the below command to restart the service:

Proceed to verify the status of your DHCP service with the command below:

Step 6: Configure Your DHCP Client Instance to Obtain a Static IP Address

Once you set up your server, you will also need to set up your client instance. The first setup procedure is to ensure that your client can obtain a static IP address from the server.

To achieve this, open your client machine. We assume your client machine has the 4c:bb:58:9c:f5:55 MAC address. Once at the device, edit its network interface using the command below:

You can edit the interface by striking off the following default lines:

Save the changes and close the file. Now, to ensure that you apply the relevant changes n the new file, you can restart your Network Manager service using the command below:

The next step is to run the command below on the client machine:

The output should be as follows:

Sometimes, you may fail to get the IP address from your DHCP server. If that is the case, you can obtain it by running the command below:

You can verify the IP address by running the command below:

Step 7: Configure Your DHCP Client Instance to Obtain a Dynamic IP Address

You can also configure your other client machine to obtain a dynamic IP address from your DHCP server. You can begin this process by first editing your network interface file using the command below:

Add the below lines to the file:

You can save and close the file. Now, to ensure that you implement the changes on the interface, proceed to restart your Network Manager using the below command:

Verify the dynamic IP address assigned to your DHCP client by running the following command:

The output should be similar to what is in the illustration below:


The article discusses the entire process beginning with installing and configuring the DHCP server on Ubuntu. We also discussed configuring the client instance to obtain both dynamic and static IP addresses.

About the author

Kennedy Brian

Brian is a computer scientist with a bias for software development, programming, and technical content development. He has been in the profession since 2015. He reads novels, jogs, or plays table tennis whenever not on gadgets. He is an expert in Python, SQL, Java, and data and network security.