Post

Dynamic Host Configuration Protocol (DHCP)

Dynamic Host Configuration Protocol (DHCP)

The Dynamic Host Configuration Protocol (DHCP) is a network management protocol used on Internet Protocol (IP) networks for automatically assigning IP addresses and other communication parameters to devices connected to the network using a client–server architecture.

Installation

1
apt install isc-dhcp-server

Usage

1
systemctl enable --now isc-dhcp-server.service
1
systemctl ( start | stop | restart ) isc-dhcp-server.service

Troubleshooting

1
systemctl status isc-dhcp-server.service
1
journalctl -xeu isc-dhcp-server.service

Network interface configuration

Edit /etc/default/isc-dhcp-server.

1
2
DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
INTERFACESv4="enp0s1 enp0s2 ..."

IP-Pool configuration

Edit /etc/dhcp/dhcpd.conf.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
option domain-name "fritz.box";
option domain-name-servers "9.9.9.9, 192.168.0.1";
default-lease-time 600;
max-lease-time 7200;
authoritative;

subnet 192.168.0.0 netmask 255.255.255.0 {
    range 192.168.0.50 192.168.0.100;
    option routers 192.168.0.1;
}

host dhcp-server {
    hardware ethernet fe:fe:fe:fe:fe:fe;
    fixed-address 192.168.0.2;
    option routers 192.168.0.1;
}
optiondescription
option domain-nameSpecifies the locally used domain name, e.g. like local.lan or something
option domain-serversSpecifies used DNS-servers
default-lease-timeLike minimum handout of an IP-address from the pool. In seconds.
max-lease-timeLike maximum handout of an IP-address from the pool. In seconds.
authoritativeThis DHCP-server is the master.
subnet 192.168.0.0 netmask 255.255.255.0 { }Subnets or IP-Pools that the server is allowed to serve
host dhcp-server { }Reservation for a specific host, this matches the MAC-address

Logging / Get info about requests and offers

Up to Debian 11 you can use:

1
tail -f -n 100 /var/log/syslog | grep dhcp
optiondescription
-fshow all following messages
-nxxshow previous xx messages

From Debian 12 and above use:

1
journalctl -fn100 -u isc-dhcp-server
optiondescription
-fshow all following messages
-nxxshow previous xx messages

Possible output:

1
2
3
4
5
6
7
8
9
10
Apr 20 09:20:42 fw dhcpd[3217]: DHCPREQUEST for 10.0.100.51 (10.0.100.1) from be:98:60:d1:af:88 via ens19: wrong network.
Apr 20 09:20:42 fw dhcpd[3217]: DHCPNAK on 10.0.100.51 to be:98:60:d1:af:88 via ens19
Apr 20 09:20:43 fw dhcpd[3217]: reuse_lease: lease age 1 (secs) under 25% threshold, reply with unaltered, existing lease for 10.0.10.50
Apr 20 09:20:43 fw dhcpd[3217]: DHCPDISCOVER from be:98:60:d1:af:88 (archiso) via ens19
Apr 20 09:20:43 fw dhcpd[3217]: DHCPOFFER on 10.0.10.50 to be:98:60:d1:af:88 (archiso) via ens19
Apr 20 09:20:43 fw dhcpd[3217]: reuse_lease: lease age 1 (secs) under 25% threshold, reply with unaltered, existing lease for 10.0.10.50
Apr 20 09:20:43 fw dhcpd[3217]: DHCPREQUEST for 10.0.10.50 (10.0.10.1) from be:98:60:d1:af:88 (archiso) via ens19
Apr 20 09:20:43 fw dhcpd[3217]: DHCPACK on 10.0.10.50 to be:98:60:d1:af:88 (archiso) via ens19
Apr 20 09:22:27 fw dhcpd[3217]: DHCPDISCOVER from fe:fe:fe:fe:fe:fe via ens20
Apr 20 09:22:27 fw dhcpd[3217]: DHCPOFFER on 192.168.0.2 to fe:fe:fe:fe:fe:fe via ens20

DHCP-Relay-Agent

A Dynamic Host Configuration Protocol (DHCP) relay agent is a network service that forwards DHCP requests from clients on one network to a DHCP server on another network. This is particularly useful in larger network environments where multiple subnets exist and maintaining a DHCP server on each subnet is not practical. Configuring a DHCP relay agent ensures that all clients, regardless of their network location, can obtain IP configuration from a centralized DHCP server.

Installation

1
apt install isc-dhcp-relay

Configuration

Edit /etc/default/isc-dhcp-relay.

1
2
3
SERVERS="192.168.19.11"
INTERFACES="enp0s9 enp0s10"
OPTIONS=""
optiondescription
SERVERS=””Here you have to specifiy the IP of your actual DHCP-Server.
INTERFACES=””You must specifiy all interfaces which transferring dhcp packets. So it have to be 2 at least.
OPTIONS=””Additional command-line options for the relay agent (optional)

Usage

1
systemctl enable isc-dhcp-relay
1
systemctl ( start | stop | restart ) isc-dhcp-relay

Troubleshooting

1
systemctl status isc-dhcp-relay
1
grep isc-dhcp-relay /var/log/syslog

You can pipe the second command through tail -n*xx* to filter the output

DHCP-Client

To troubleshoot clients in your network and test if the configured DHCP-server is working properly here some basic commands to force the client to obtain a new IP or renew the lease of the actual offered IP.

Installation

1
apt install isc-dhcp-common

Usage

Do a new IP-request:

1
dhclient

Do an IP-Renew:

1
dhclient -r
This post is licensed under CC BY 4.0 by the author.