5 min read

Configuring a DHCP Server on a Unix-Based System: A Comprehensive Guide

Configuring a DHCP Server on a Unix-Based System: A Comprehensive Guide

Installation and configuration of a DHCP Server on a Unix based machine.
Operating System: Raspbian GNU/Linux 10 (buster).
DHCP Server: isc-dhcp-server 4.4.1-2.1.

Overview

DHCP (Dynamic Host Configuration Protocol) is a local network protocol with the primary purpose of automatically providing network configuration to clients that connect to the network without preconfigured settings. This configuration primarily includes an IP address, default gateway, and DNS server information.

DHCP operates on the client-server communication model and uses the UDP/IP suite. Whenever a client requests network configuration, the DHCP server selects a network configuration from its pool (domain) of addresses, previously configured by the network administrator. It then forwards this configuration to the client, making it unavailable for other requests to prevent IP address conflicts (two hosts cannot have the same IP address on a network). The client subsequently updates its network configuration with the received information.

The number of possible configurations is limited and set by the administrator.

The DHCP request process functions as follows:

  • The client seeking configuration sends a DHCPDISCOVER broadcast packet containing its MAC address.
  • The DHCP server analyzes the MAC address in the request and responds to the client with a DHCPOFFER packet.
  • If the client accepts the configuration, it responds with a DHCPREQUEST broadcast packet (since there could be multiple DHCP servers) containing the server identifier, which is the ID of the DHCP server the client chooses to interact with.
  • The server replies with DHCPACK, an acknowledgment packet that finalizes the communication.

A network can have multiple DHCP servers, often organized hierarchically. This means that the request must be initially processed by the primary server (referred to as authoritative), which can either respond directly or forward the request to a subordinate server, which will make a similar choice.

Furthermore, each DHCP response has a lease time, a period specified by the server. Once this time expires, the configuration becomes invalid, and the client must request a new DHCP lease. This feature allows the DHCP server to reclaim IP addresses from devices that have disconnected from the network and redistribute them to new devices that may connect.

Section 1: Installation

The first step is to install the ISC's DHCP Server DHCPd on our Unix-based system. ISC's DHCP Server works as a daemon process (the d stands for daemon), a background process that runs independently of user interactions. To install DHCPd, follow these steps:

Open a terminal window on your Unix-based system.

  • Update the package list by running:
sudo apt update
  • Install ISC DHCP with the following command:
sudo apt install isc-dhcp-server
  • Once the installation is complete, start the ISC DHCP service and enable it to start on boot with these commands:
sudo systemctl start isc-dhcp-server
sudo systemctl enable isc-dhcp-server

Section 2: Configuration

This section outlines the configuration of the dhcpd daemon on Unix-based systems. The configuration file, /etc/dhcp/dhcpd.conf, is dissected to understand its elements and implications.

Section 2.1: Configuration Details

Define the subnet in the /etc/dhcp/dhcpd.conf file:

subnet 192.168.9.0 netmask 255.255.255.0
{
  authoritative;
  range 192.168.9.100 192.168.9.254;
  option routers 192.168.9.2;
  option domain-name "gruppo9.labreti.it";
  option domain-name-servers 192.168.9.2;
  default-lease-time 3600;
  max-lease-time 86400;
  deny unknown-clients;
}

.
.
.

host computer1
{
  hardware ethernet e8:6a:64:6e:12:08;
  fixed-address 192.168.9.1;
}

In this specific configuration, a subnet is established with address 192.168.9.0 with a netmask of 255.255.255.0. To operate within this subnet, the server must possess an IP address falling within the range of 192.168.9.x, where 1 < x < 254. It's crucial to assign the DHCP server itself a static IP address, typically configured in the /etc/network/interfaces file, with the same address 192.168.9.2 as in the previous file. By setting the authoritative flag, this DHCP server is designated as the primary server for this subnet, taking precedence in responding to DHCP requests. Furthermore, the range parameter defines the span of IP addresses available for distribution by the DHCP server, specified as addresses between 100 and 254. The router field indicates the default gateway suggested to client devices, while the domain-name-servers field specifies the DNS server addresses recommended for client configuration. Additionally, the lease duration governs the availability of server-provided information to clients, measured in seconds. Two lease values exist: default and max, with max establishing the upper time limit for lease validity. The deny unknown-clients option instructs the server not to allocate IP addresses to clients with unknown MAC addresses.

In the final part of the configuration, a unique address assignment is defined for a specific device identified by the MAC address e8:6a:64:6e:12:08, which is set as 192.168.9.1. The assignment for computer1 has a global scope because, in this specific setup, the device associated with the MAC address e8:6a:64:6e:12:08 must consistently use the same address. This ensures that whenever this particular device connects to the network, it will consistently receive the same identical IP address.

Section 2.2: DHCPv6 Configuration

The DHCP protocol is divided into DHCPv4 and DHCPv6 due to the fundamental differences in how IPv4 and IPv6 operate. IPv6 was designed to utilize SLAAC (Stateless Address Auto-Configuration), distinguishing it from IPv4.

In IPv6, each interface can potentially have two types of addresses:

  1. Link-Local Address: This address, generated from the MAC address and within the fe80::/64 prefix, is valid only within a LAN and facilitates self-configured communication in networks without a DHCP server.
  2. Global Scope Address: Obtainable in two ways: DHCP or through routers. Once a client configures its link-local address, it sends a "Router Solicitation (RS)" message to the ff02::2 broadcast address. Routers within the network respond with a "Router Advertisement (RA)" containing available IPv6 addresses. Typically, a DHCPv6 server's role in a network is to provide information other than IP addresses or gateways, such as DNS server details, domain suffixes, etc., as the primary information is conveyed by routers.

DHCPv6 can also assign global addresses, known as "Stateful Address Configuration." In this case, the router does not respond with an RA but instead signals the client to request an IPv6 address from a DHCPv6 server.

It's important to note that a DHCPv6 server does not provide default gateway information as this data must be obtained from the router via an RA.

File: /etc/default/isc-dhcp-server:

# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)
# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf
# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid
# Additional options to start dhcpd with.
#
Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID
instead
#OPTIONS=""
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#
Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="enx847beb214075"
INTERFACESv6="

This file contains configuration options for the DHCP server:

  • DHCPDv4_CONF and DHCPDv6_CONF specify the paths to the DHCP server configuration files, with default values of /etc/dhcp/dhcpd.conf and /etc/dhcp/dhcpd6.conf, respectively.
  • DHCPDv4_PID and DHCPDv6_PID specify the paths to the PID (Process ID) files for the DHCP servers.
  • OPTIONS allows for additional options to start DHCP servers with, without using -cf or -pf options. However, these options should be defined using DHCPD_CONF and DHCPD_PID.

Additionally, the INTERFACESv4 and INTERFACESv6 variables indicate the interfaces on which the DHCP servers (dhcpd) should serve DHCP requests for IPv4 and IPv6, respectively. In this configuration, the IPv6 DHCP server serves the "enx847beb214075" interface.

This DHCPv6 setup optimizes IPv6 network configuration by efficiently allocating global addresses and other essential network information to clients.

Section 3: Conclusion

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.