Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Configuring DHCP

Introduction

Dynamic Host Configuration Protocol (DHCP) is a network management protocol used to dynamically assign IP addresses to devices on a network. This tutorial will guide you through the process of configuring a DHCP server on a Linux system.

Prerequisites

Before you start, ensure you have the following:

  • A Linux system with root or sudo access.
  • Basic understanding of network concepts.

Step 1: Install DHCP Server

First, you need to install the DHCP server package. On most Linux distributions, this can be done using the package manager.

sudo apt-get update

sudo apt-get install isc-dhcp-server

On CentOS or RHEL, use the following commands:

sudo yum install dhcp

Step 2: Configure DHCP Server

The main configuration file for the DHCP server is /etc/dhcp/dhcpd.conf. Open this file in your preferred text editor:

sudo nano /etc/dhcp/dhcpd.conf

Add the following configuration to define a subnet and IP address range:

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.10 192.168.1.100;
    option routers 192.168.1.1;
    option subnet-mask 255.255.255.0;
    option domain-name-servers 8.8.8.8, 8.8.4.4;
    option domain-name "example.com";
}
                

This configuration defines a subnet 192.168.1.0/24 and assigns IP addresses from 192.168.1.10 to 192.168.1.100. Adjust these values according to your network configuration.

Step 3: Assign Static IP Addresses

To assign a static IP address to a specific device, add a host declaration within the subnet block:

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

Step 4: Start the DHCP Server

After configuring the DHCP server, start the service:

sudo systemctl start isc-dhcp-server

sudo systemctl enable isc-dhcp-server

On CentOS or RHEL:

sudo systemctl start dhcpd

sudo systemctl enable dhcpd

Step 5: Verify DHCP Server

To verify that the DHCP server is running correctly, check its status:

sudo systemctl status isc-dhcp-server

You can also check the DHCP leases file to see the assigned IP addresses:

sudo cat /var/lib/dhcp/dhcpd.leases

Conclusion

You have successfully configured a DHCP server on your Linux system. DHCP simplifies network management by automatically assigning IP addresses to devices, making it an essential tool for network administrators.