Install DHCP Server on Debian 11

This article is going to take you through on how to Install DHCP Server on Debian 11. The DHCP Server is a network server that automatically assigns IP addresses, default gateways, and other network information to client devices. To reply to broadcast queries from clients, the DHCP server employs the Dynamic Host Configuration Protocol (DHCP).

How to Install DHCP Server on Debian 11

  • Update your packages.
sudo apt update
  • Then run the command below to install DHCP Server.
sudo apt install isc-dhcp-server

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libirs-export161 libisccfg-export163 policycoreutils
  selinux-utils
Suggested packages:
  isc-dhcp-server-ldap
The following NEW packages will be installed:
  isc-dhcp-server libirs-export161 libisccfg-export163
  policycoreutils selinux-utils
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,702 kB of archives.
After this operation, 6,915 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian bullseye/main amd64 libisccfg-export163 amd64 1:9.11.19+dfsg-2.1 [272 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 libirs-export161 amd64 1:9.11.19+dfsg-2.1 [245 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 isc-dhcp-server amd64 4.4.1-2.3 [553 kB]
Get:4 http://deb.debian.org/debian bullseye/main amd64 selinux-utils amd64 3.1-3 [142 kB]
Get:5 http://deb.debian.org/debian bullseye/main amd64 policycoreutils amd64 3.1-3 [491 kB]
Fetched 1,702 kB in 1s (1,270 kB/s)  
Preconfiguring packages ...
Selecting previously unselected package libisccfg-export163.
(Reading database ... 142616 files and directories currently installed.)
Preparing to unpack .../libisccfg-export163_1%3a9.11.19+dfsg-2.1_amd64.deb ...
Unpacking libisccfg-export163 (1:9.11.19+dfsg-2.1) ...
Selecting previously unselected package libirs-export161.
Preparing to unpack .../libirs-export161_1%3a9.11.19+dfsg-2.1_amd64.deb ...

Configure DHCP Server on Debian 11

  • Configure your DHCP server to listen on an interface by editing the config /etc/default/isc-dhcp-server, open it using the command below.
sudo nano /etc/default/isc-dhcp-server
  • Next, define your network interface, check your network interface using the command ip a. Note, The IP addresses will be obtained by connecting to this interface.
INTERFACESv4="ens33"
  • You can also define multiple interfaces by spacing the names out as shown in the example below.
INTERFACESv4="ens33 ens34"
  • This is the interface that will be utilized to serve DHCP requests on my server.
ip a show dev ens33

Sample output

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:e6:b6:d0 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.0.103/24 brd 192.168.0.255 scope global dynamic noprefixroute ens33
       valid_lft 4817sec preferred_lft 4817sec
    inet6 fe80::20c:29ff:fee6:b6d0/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

When you’re finished with the configurations, save and exit the file.

  • Start the DHCP server using the following command.
sudo systemctl start isc-dhcp-server
  • Allow the DHCP server to start automatically on system boot.
systemctl enable isc-dhcp-server
  • After that, you can set up your DHCP server in the /etc/dhcp/dhcpd.conf config file. Open the file using the following command.
sudo  nano /etc/dhcp/dhcpd.conf
  • If applicable, specify your domain name and DNS nameservers.
option domain-name "itnixpro.com";
option domain-name-servers ns1.itnixpro.com, ns2.itnixpro.com;
  • Next, set the maximum lease time.
default-lease-time 3600;
max-lease-time 43200;

Above meaning;

  • default-lease-time:When a client does not request a specific lease, the default lease time is used.
  • max-lease-time: determines how long the server can allocate a lease.
  • Uncomment the argument authoritative to make the DHCP server the official DHCP server for the local network.
authoritative;
  • By uncommenting the line below, DHCP server will transmit dhcp log messages to an alternative log file.
log-facility local7
  • Define the DHCP network IP range after that.
subnet 192.168.0.0 netmask 255.255.255.0 {
 range 192.168.0.100 192.168.0.200;
 option routers 192.168.0.1;
 option domain-name "itnixpro.com"
 option domain-name-servers 192.168.0.1, 8.8.8.8;
}

Above config meaning

  • IP range
  • gateway/router address
  • domain name servers
  • domain names

Save and close the file.

  • We enabled syslog logging. As a result, set up syslog to log DHCP events like below;
echo "local7.* /var/log/dhcpd.log" | sudo tee /etc/rsyslog.d/51-dhcpd.conf
  • To prevent DHCP from logging twice to /var/log/syslog and /var/log/dhcpd.log, modify the syslog logging by adding the line local7.none to facilities that log to /var/log/syslog;
sed -i '/\/var\/log\/syslog/s/none/none,local7.none/' /etc/rsyslog.d/50-default.conf
  • The following is how the line should now appear:
grep '/var/log/syslog' /etc/rsyslog.d/50-default.conf
*.*;auth,authpriv.none,local7.none        -/var/log/syslog
  • Restart Rsyslog
sudo systemctl restart rsyslog

Open DHCP Server Ports on Firewall

  • Allow DHCP port on firewall using the command below.
sudo ufw allow  67/udp
  • To apply the modifications, restart the DHCP server.
sudo systemctl restart isc-dhcp-server.service
  • Check that the DHCP server is up and running using the command below.
sudo systemctl status isc-dhcp-server

Sample output

● isc-dhcp-server.service - LSB: DHCP server
     Loaded: loaded (/etc/init.d/isc-dhcp-server; generated)
     Active: active (running) since Fri 2022-04-22 12:32:17 EAT; 19s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 4078 ExecStart=/etc/init.d/isc-dhcp-server start (code=exited, status=0/SUCCESS)
      Tasks: 4 (limit: 4623)
     Memory: 4.6M
        CPU: 58ms
     CGroup: /system.slice/isc-dhcp-server.service
             └─4094 /usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf ens33

Apr 22 12:32:15 debian systemd[1]: Starting LSB: DHCP server...
Apr 22 12:32:15 debian isc-dhcp-server[4078]: Launching IPv4 server only.
Apr 22 12:32:15 debian dhcpd[4094]: Wrote 0 leases to leases file.
Apr 22 12:32:15 debian dhcpd[4094]: Server starting service.
Apr 22 12:32:17 debian isc-dhcp-server[4078]: Starting ISC DHCPv4 server: dhcpd.
Apr 22 12:32:17 debian systemd[1]: Started LSB: DHCP server.
  • Check the logs as well.
tail -f /var/log/dhcpd.log

Check how to configure DHCP clients on the guide below

How to Configure DHCP Client on Ubuntu

  • You have made it to the end of our article. Congrats! you have learned how to Install DHCP Server on Debian 11.

Read more about DHCP

Other Tutorials

Install NFS Server on Ubuntu 22.04

Install and configure Postfix as Send-Only SMTP on Debian 11

Install Filebeat 8 on Rocky Linux

System administrator | Software Developer | DevOps

1 thought on “Install DHCP Server on Debian 11”

  1. For Debian 11 ARM (and Pi OS 11), I found local7 referenced in /etc/rsyslog.conf only, no files under /etc/rsyslog.d until the 51-dhcpd.conf is created. You may want to add a comment that the variance exists in Debian 11 ARM.

    Reply

Leave a Comment