Marcio Cunha

How to Install and Configure a DHCP Server on Ubuntu

Learn how to install, configure, and manage the ISC DHCP Server on Ubuntu systems to automate IP address distribution across your local network securely and reliably.

Marcio Cunha12 min
Also available in:EspañolPortuguês
Summary
  • Automating IP address assignment eliminates manual errors and network conflicts caused by duplicate addresses.
  • Using static leases ensures that servers and network printers always keep the exact same IP address.
  • Regular system log monitoring prevents silent failures in the distribution of network configuration parameters.
  • Defining appropriate lease times balances client stability with overall network address flexibility.
  • Choosing the correct network interface prevents the DHCP server from leaking IP assignments into corporate networks.

Fundamentals of the DHCP Protocol in Local Networks

When we connect a device to a computer network, it needs an IP address (Internet Protocol, which acts as the digital mailing address of the device) to communicate with other equipment. Doing this manually across dozens or hundreds of machines would be an operational nightmare. This is precisely where DHCP (Dynamic Host Configuration Protocol) comes into play, acting as a smart receptionist that distributes temporary identification badges to every new visitor.

In practice, the DHCP server stores a block of available IP addresses and lends them to devices as they join the network. Beyond the numerical address, the server also provides crucial information such as the subnet mask (which defines the size of the local neighborhood), the default gateway (the exit door to the internet), and DNS servers (which translate website names into IP addresses). Without this system, managing modern networks would be completely unviable in terms of time and technical support overhead.

Before getting hands-on with Ubuntu, it is worth understanding the underlying trade-offs. Although automation brings massive agility, it also requires security awareness, because any connected device will automatically receive an IP unless additional control mechanisms are enforced, such as MAC address filtering (Media Access Control, the unique identifier hardcoded into every network interface card). Proper configuration ensures the perfect balance between convenience and operational control.

Installing the ISC DHCP Server on Ubuntu

The Linux ecosystem offers several tools for this task, but the most traditional, robust, and widely tested package in production environments is the ISC DHCP Server (historically known as dhcpd). To get started, the first practical step is to update your Ubuntu system package list to ensure you are downloading the most stable and secure version available in official repositories.

Open your terminal and run the update command followed by the installation command. In practice, this tells the operating system to fetch the required files from the internet and install them automatically:

sudo apt update
sudo apt install isc-dhcp-server -y

As soon as the installation process finishes, it is very common for the service to try starting immediately and report a failure. Do not panic: this happens because the DHCP server does not yet know which network interface it should listen on for client requests. The program is disabled by default to prevent you from accidentally distributing IP addresses in a corporate network or public internet before performing the necessary adjustments.

Configuring the Network Interface and Initial Parameters

The next critical step involves telling the DHCP server which physical network interface it must monitor. On modern Ubuntu servers, we use system configuration files to bind the service to a specific interface. To edit the ISC DHCP package configuration file, we use a terminal text editor like nano.

Open the startup configuration file with administrative privileges:

sudo nano /etc/default/isc-dhcp-server

Inside this file, locate the line starting with INTERFACESv4="" and insert the name of your primary network interface between the quotes. For instance, if your interface is named eth0 or enp3s0, the line should look like INTERFACESv4="enp3s0". Save the file and close the editor, keeping in mind that correct interface identification prevents the server from attempting to answer requests on incorrect ports.

Before proceeding to the main rules file, it is essential that the Ubuntu machine hosting the DHCP server has a static (fixed) IP address. If the server itself changes its IP address upon every reboot, the entire network will lose the reference point of who manages leases, triggering a complete collapse in internal communication.

Structuring the Main Configuration File

With the interface defined and the static IP secured, the heart of the configuration lies within the /etc/dhcp/dhcpd.conf file. This is where we define the range of IPs to be distributed (the scope), how long each device can keep that address, and the DNS server addresses passed down to clients.

Open the main file using the text editor:

sudo nano /etc/dhcp/dhcpd.conf

Inside this file, you will find several commented lines (starting with semicolons or hash marks). For a basic and functional setup in a typical local network, add a structured block like the example below, adapting the values to fit your infrastructure:

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.100 192.168.1.200;
  option routers 192.168.1.1;
  option domain-name-servers 8.8.8.8, 1.1.1.1;
  option domain-name "my-local-network.local";
  default-lease-time 600;
  max-lease-time 7200;
}

In practice, the block above dictates the following: for network 192.168.1.0 with subnet mask 255.255.255.0, lend addresses between 192.168.1.100 and 192.168.1.200. The default router is 192.168.1.1, and computers must use Google and Cloudflare DNS servers. The default lease time is 10 minutes, extending up to a maximum of 2 hours if the device remains connected.

Assigning Static IPs for Critical Devices

Across any network infrastructure, certain equipment cannot afford to change its IP address under any circumstances. File servers, network printers, security cameras, and Wi-Fi access points require predictability so users can always find them at the exact same logical location. To solve this, DHCP allows you to create reservations based on the MAC address of the equipment's network interface card.

To configure a fixed IP for a specific device, return to the /etc/dhcp/dhcpd.conf file and add a host declaration inside your subnet statement. The format is clean and straightforward, ensuring that specific hardware always receives identical treatment:

host floor-1-printer {
  hardware ethernet 00:11:22:33:44:55;
  fixed-address 192.168.1.50;
}

This approach combines the best of both worlds: you centralize network-wide management on the DHCP server, eliminating complex manual tracking spreadsheets, while ensuring critical assets maintain fixed, predictable addresses. Make sure your reserved IPs fall outside the dynamic address range to prevent duplication conflicts.

Validation, Startup, and Troubleshooting

After writing and adjusting all rules in the configuration file, the most crucial step before taking the service live is syntax validation. A single forgotten character, such as a semicolon at the end of a line, is enough to prevent the server from starting correctly.

Run the verification command provided directly by the package to test the configuration file:

sudo dhcpd -t

If the command returns without errors, you can safely proceed to enable and start the service within systemd, Ubuntu's service manager:

sudo systemctl enable isc-dhcp-server
sudo systemctl restart isc-dhcp-server

To confirm that everything runs smoothly, check the current service status via sudo systemctl status isc-dhcp-server. If any issues arise, the command journalctl -u isc-dhcp-server -e will display detailed system logs, allowing you to pinpoint the exact configuration line causing the impasse and fix it immediately.

Final Considerations on DHCP Server Operation

Successfully deploying a DHCP server on Ubuntu transforms local network administration, replacing repetitive manual labor with an automated, auditable, and highly customizable process. Throughout this guide, we explored everything from installing core packages to creating static reservations for critical hardware, establishing a rock-solid foundation for any corporate or advanced home infrastructure.

Maintaining a healthy network requires ongoing attention to system logs, proper IP address range planning, and periodic testing following any structural changes. Armed with the concepts and commands presented here, you now possess full autonomy to manage leases, prevent IP conflicts, and guarantee absolute stability in communication across all connected devices.