UbuntuUbuntu Based

How To Set Up DHCP Server on Ubuntu 24.04 LTS

Set Up DHCP Server on Ubuntu 24.04

In today’s interconnected world, managing a network efficiently is crucial for businesses and organizations of all sizes. One of the essential components of network management is the Dynamic Host Configuration Protocol (DHCP), which automates the process of assigning IP addresses to devices on a network. In this comprehensive guide, we will walk you through the steps to set up a DHCP server on Ubuntu 24.04 LTS, a popular and reliable Linux distribution.

Understanding DHCP

Before diving into the setup process, let’s take a moment to understand what DHCP is and how it benefits network management. DHCP is a network protocol that automatically assigns IP addresses, subnet masks, default gateways, and other network configuration parameters to devices on a network. By using a DHCP server, network administrators can save time and effort, as they no longer need to manually configure each device’s network settings.

In a DHCP-enabled network, when a device connects to the network, it sends a broadcast message requesting an IP address. The DHCP server receives this request and assigns an available IP address from a predefined pool, along with other necessary network configuration details. This process is known as an IP lease, and the DHCP server keeps track of which IP addresses are assigned to which devices.

Prerequisites

Before setting up a DHCP server on Ubuntu 24.04 LTS, ensure that your system meets the following requirements:

  • A fresh installation of Ubuntu 24.04 LTS with a minimum of 2 GB RAM and 20 GB storage space.
  • Sudo access to execute commands with administrative privileges.
  • Two network interfaces: one for management and one for the DHCP service. The management interface will be used to access the server, while the DHCP interface will be used to serve IP addresses to clients.

Installation of ISC-DHCP-Server

The first step in setting up a DHCP server on Ubuntu 24.04 LTS is to install the ISC-DHCP-Server package. This package provides the necessary components to run a DHCP server on your system. To install it, follow these steps:

  1. Open a terminal window and update the package index by running the following command:
    sudo apt update
  2. Once the package index is updated, install the ISC-DHCP-Server package using the following command:
    sudo apt install isc-dhcp-server
  3. The installation process will download and install the necessary files. After the installation is complete, you can verify the installation by checking the version of the installed package:
    dhcpd --version

Configuring the DHCP Server

With the ISC-DHCP-Server package installed, the next step is to configure the DHCP server. This involves editing two main configuration files: /etc/default/isc-dhcp-server and /etc/dhcp/dhcpd.conf.

Configuring Network Interfaces

First, let’s configure the network interfaces that the DHCP server will use. Open the /etc/default/isc-dhcp-server file using a text editor with sudo privileges:

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

In this file, locate the INTERFACESv4 option and specify the network interface that will be used for the DHCP service. For example, if your DHCP interface is enp0s8, update the line as follows:

INTERFACESv4="enp0s8"

Save the changes and exit the text editor.

Configuring DHCP Settings

Next, we’ll configure the main DHCP settings in the /etc/dhcp/dhcpd.conf file. Open the file using a text editor with sudo privileges:

sudo nano /etc/dhcp/dhcpd.conf

In this file, you’ll find various configuration options. Let’s go through the essential settings:

  1. Set the domain name and DNS servers:
    option domain-name "example.com";
    option domain-name-servers 8.8.8.8, 8.8.4.4;

    Replace example.com with your domain name and adjust the DNS server IP addresses as needed.

  2. Define the subnet and IP address range:
    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;
    }

    Adjust the subnet, netmask, IP address range, and default gateway (routers) according to your network configuration.

  3. Set the lease time:
    default-lease-time 600;
    max-lease-time 7200;

    The default-lease-time specifies the default duration (in seconds) for which an IP address is leased to a client. The max-lease-time sets the maximum duration. Adjust these values based on your requirements.

Save the changes and exit the text editor.

Starting and Enabling the DHCP Service

With the configuration files updated, you can now start the DHCP service and enable it to start automatically at boot. Use the following commands:

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

To verify that the DHCP service is running correctly, use the following command:

sudo systemctl status isc-dhcp-server

If the service is active and running, you’ll see output similar to the following:

● isc-dhcp-server.service - ISC DHCP IPv4 server
     Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2024-10-03 10:00:00 UTC; 5min ago
       Docs: man:dhcpd(8)
   Main PID: 1234 (dhcpd)
      Tasks: 1 (limit: 1234)
     Memory: 6.2M
        CPU: 10ms
     CGroup: /system.slice/isc-dhcp-server.service
             └─1234 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf enp0s8

Configuring a DHCP Client

Now that the DHCP server is up and running, let’s configure a client machine to obtain an IP address from the server. The steps may vary depending on the client operating system, but we’ll provide a general example using Ubuntu.

  1. On the client machine, open the network configuration file:
    sudo nano /etc/netplan/01-netcfg.yaml
  2. Update the configuration to use DHCP:
    network:
      version: 2
      ethernets:
        enp0s3:
          dhcp4: true

    Replace enp0s3 with the actual network interface name on the client machine.

  3. Save the changes and exit the text editor.
  4. Apply the new network configuration:
    sudo netplan apply

The client machine should now obtain an IP address from the DHCP server. You can verify the assigned IP address by running the following command on the client:

ip addr show

Troubleshooting Common Issues

If you encounter any issues while setting up or using the DHCP server, here are a few troubleshooting tips:

  • Check the DHCP server logs for any error messages:
    sudo tail -f /var/log/syslog | grep dhcpd
  • Verify that the DHCP server is listening on the correct network interface:
    sudo netstat -uap | grep dhcpd
  • Ensure that the firewall is allowing DHCP traffic (UDP ports 67 and 68).
  • Double-check the configuration files for any syntax errors or incorrect settings.
  • Restart the DHCP service after making any changes to the configuration files:
    sudo systemctl restart isc-dhcp-server

Advanced Configuration Options

While the basic setup of a DHCP server on Ubuntu 24.04 LTS covers most use cases, there are several advanced configuration options available for more complex network environments. Some of these options include:

  • Dynamic DNS updates: Configuring the DHCP server to update DNS records automatically when assigning IP addresses to clients.
  • Lease time adjustments: Fine-tuning the lease duration based on network requirements and device types.
  • Security settings: Implementing access control lists (ACLs) and secure DHCP options to enhance network security.
  • Multiple subnets and VLANs: Configuring the DHCP server to serve IP addresses across multiple subnets and VLANs.
  • ISC-Kea: Exploring ISC-Kea as an alternative DHCP server software with advanced features and a RESTful API for management.

Congratulations! You have successfully configured the DHCP server. Thanks for using this tutorial to set up the DHCP server on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Ubuntu website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button