Dynamic Host Configuration Protocol (DHCP) is a network management protocol used to automate the assignment of IP addresses to devices on a network. This guide will walk you through the process of installing and configuring a DHCP server on an Ubuntu system.
Table of Contents
Introduction to DHCP
What is DHCP?
DHCP is a protocol used to automatically assign IP configurations to clients on a network. This can be extremely useful for managing large pools of devices that need specific network settings. By using a DHCP server, you can easily update and manage the network configuration across multiple devices without needing to configure each one individually.
DHCP Configuration Methods
DHCP can be configured in several ways:
Manual Allocation: The configuration settings are bound to the MAC address of the client’s network card. Each time the client makes a request, it receives the same network settings.
Dynamic Allocation: A range of IP addresses is specified, and the server assigns IP addresses dynamically from this pool on a first-come, first-served basis. This method includes a lease time, which defines how long a client can use an IP address before needing to renew the lease.
Getting Ready
Before installing a DHCP server, ensure your DHCP host is configured with a static IP address. Also, make sure you have root or sudo privileges.
Installing the DHCP Server
Installation Steps
Follow these steps to install the DHCP server software:
Install the DHCP server package:
sudo apt-get install isc-dhcp-server
Open the DHCP configuration file:
sudo nano -w /etc/dhcp/dhcpd.conf
Edit the configuration file:
Adjust the default and maximum lease times if necessary:
default-lease-time 600;
max-lease-time 7200;
Parameters:
- default-lease-time 600;
Description: This setting specifies the default lease duration in seconds. It means that by default, an IP address is assigned to a device for 600 seconds (which equals 10 minutes).
Purpose: If the DHCP client does not request a specific lease time, it will be assigned this default lease period. A shorter default lease time is beneficial in highly dynamic environments where devices frequently join and leave the network.
- max-lease-time 7200;
Description: This setting specifies the maximum lease duration in seconds. It means that the maximum time an IP address can be assigned to a device is 7200 seconds (which equals 2 hours).
Purpose: This prevents clients from holding IP addresses for too long, ensuring efficient usage of the available IP address pool. It sets an upper limit to the lease time requested by DHCP clients.
How Lease Time Works
Lease Renewal: The client must renew its lease before it expires. Typically, a DHCP client will start trying to renew its lease halfway through the lease period.
Lease Expiration: If the lease expires and the client does not renew it, the IP address is returned to the pool of available addresses, making it available for assignment to other devices.
Add a subnet declaration at the end of the file, replacing the IP addresses with your network settings:
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.150 192.168.1.200;
option routers 192.168.1.1;
option domain-name-servers 192.168.1.2, 192.168.1.3;
option domain-name "example.com";
}
Save and close the file:
Ctrl + O (to save) Then Ctrl + X (to exit)Restart the DHCP service:
sudo service isc-dhcp-server restart
How it Works
The DHCP server employs the isc-dhcp-server package, supporting both IPv4 and IPv6. The configuration file /etc/dhcp/dhcpd.conf contains all the settings needed for the DHCP server to function. When configured, the DHCP server dynamically assigns IP addresses within the specified range and provides information such as default gateways and DNS servers.
Advanced Configuration
IP Address Reservation
To reserve specific IP addresses for devices, ensuring they consistently receive the same IP, you can add entries in the configuration file with each device’s MAC address. Below is a combined example to reserve IP addresses for two devices:
host Device1 {
hardware ethernet 08:D2:1F:50:F0:6F;
fixed-address 192.168.1.201;
}
host Device2 {
hardware ethernet 00:1A:2B:3C:4D:5E;
fixed-address 192.168.1.202;
}
These configurations ensure that the device with the MAC address 08:D2:1F:50:F0:6F always receives the IP address 192.168.1.201
And the device with the MAC address 00:1A:2B:3C:4D:5E always receives the IP address 192.168.1.202. Add the above code to your dhcpd.conf file to set up these reservations.
Conclusion
Setting up a DHCP server on Ubuntu is a straightforward process that can significantly ease network management tasks. By following this guide, you can automate IP address assignment and ensure seamless network configuration across your devices. For more advanced configurations, consider exploring additional options and parameters available in the DHCP configuration files.



