This article is going to take you through on how to Install DHCP Server on Ubuntu 22.04. The DHCP Server is a network server that allocates IP addresses, default gateways, and other network information to client devices automatically. DHCP server uses standard protocol known as Dynamic Host Configuration Protocol(DHCP) to respond to broadcast queries by clients.
How to Install DHCP Server on Ubuntu 22.04
Install DHCP Server on Ubuntu 22.04
- Update your packages.
sudo apt update
- Then install DHCP Server using the command below.
sudo apt install isc-dhcp-server
Sample output
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: fonts-open-sans gir1.2-gnomebluetooth-1.0 i965-va-driver intel-media-va-driver kwayland-data libaacs0 libavcodec58 libavformat58 libavutil56 libbdplus0 libbluray2 libchromaprint1 libcodec2-1.0 libdouble-conversion3 libgme0 libgsm1 libigdgmm12 libkf5waylandclient5 libmd4c0 libmfx1 libminizip1 libmng2 libnorm1 libopenal-data libopenal1 libopenmpt0 libpcre2-16-0 libpgm-5.3-0 libqrcodegencpp1 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5svg5 libqt5waylandclient5 libqt5widgets5 librabbitmq4 librlottie0-1 libshine3 libsndio7.0 libsrt1.4-gnutls libssh-gcrypt-4 libswresample3 libswscale5 libudfread0 libva-drm2 libva-x11-2 libva2 libvdpau1 libx264-163 libxcb-record0 libxcb-screensaver0 libxcb-xinerama0 libxcb-xinput0 libxvidcore4 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers mesa-vdpau-drivers qt5-gtk-platformtheme qt5-image-formats-plugins qttranslations5-l10n va-driver-all vdpau-driver-all Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libirs-export161 libisccfg-export163 Suggested packages: isc-dhcp-server-ldap policycoreutils The following NEW packages will be installed: isc-dhcp-server libirs-export161 libisccfg-export163 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Need to get 528 kB of archives. After this operation, 1,545 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libisccfg-export163 amd64 1:9.11.19+dfsg-2.1ubuntu3 [53.0 kB] Get:2 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libirs-export161 amd64 1:9.11.19+dfsg-2.1ubuntu3 [20.0 kB] Get:3 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 isc-dhcp-server amd64 4.4.1-2.3ubuntu2 [455 kB] Fetched 528 kB in 0s (1,517 kB/s)
Configure DHCP Server on Ubuntu 22.04
- To begin with configure to listen on an interface.
- You can configure your DHCP server by editing the config file located at
/etc/default/isc-dhcp-server
. Open the config file with text editor of your choice.
- You can configure your DHCP server by editing the config file located at
sudo nano /etc/default/isc-dhcp-server
- Then define your network interface as in the example below. After that save and close the file.
- You can check your network interface using the command
ip a
. - Note that this is the interfaces that the DHCP server (dhcpd) serve should DHCP requests on. Clients will connect to this interface to get the IP addresses.
INTERFACESv4="ens33"
If you have multiple interfaces, then you can define them space separated enclosed within the quote;
INTERFACESv4="ens33 ens34"
On my server, this is the interface that will be used to server DHCP requests;
ip a show dev ens33
4: ens33:mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:40:84:d0 brd ff:ff:ff:ff:ff:ff inet 192.168.0.1/24 brd 192.168.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe40:84d0/64 scope link valid_lft forever preferred_lft forever
- Save and exit the file when done with configurations.
- Start DHCP server using the following command.
sudo systemctl start isc-dhcp-server
- Enable DHCP server to start on system boot.
systemctl enable isc-dhcp-server
- Next, you can configure your DHCP server. The default config file is located at
/etc/dhcp/dhcpd.conf
To do that open the file using the command below.
sudo nano /etc/dhcp/dhcpd.conf
- Define your domain name and DNS nameservers, if applicable;
option domain-name "itnixpro.com";
option domain-name-servers ns1.itnixpro.com, ns2.itnixpro.com;
- Define the default and maximum lease time;
default-lease-time
: is the lease time used if the client does not request a specific lease.max-lease-time
: defines the longest lease that the server can allocate
default-lease-time 3600;
max-lease-time 43200;
- Configure the DHCP server as official DHCP server for the local network by uncommenting the parameter, authoritative.
authoritative;
- Configure DHCP server to send dhcp log messages to a different log file by uncommenting the line;
log-facility local7
- Define the DHCP network IP range.
- IP range
- gateway/router address
- domain name servers
- domain names
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;
}
- And those are the only changes we will use in this setup.Save and exit the configuration file when done with configuration.
- We enabled syslog logging. Thus, configure syslog to log DHCP events as follows;
echo "local7.* /var/log/dhcpd.log" | sudo tee /etc/rsyslog.d/51-dhcpd.conf
Now, to avoid DHCP double logging to /var/log/syslog and to /var/log/dhcpd.log, you need to make some changes to syslog logging by adding the line local7.none
to facilities that logs to /var/log/syslog;
sed -i '/\/var\/log\/syslog/s/none/none,local7.none/' /etc/rsyslog.d/50-default.conf
The line should now look like;
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.
sudo ufw allow 67/udp
- Restart DHCP server to apply changes.
sudo systemctl restart isc-dhcp-server.service
- DHCP server should be up and running, check status using the command below.
sudo systemctl status isc-dhcp-server
Sample output
● 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 Wed 2022-04-27 18:25:42 EAT; 1s ago Docs: man:dhcpd(8) Main PID: 5781 (dhcpd) Tasks: 4 (limit: 2292) Memory: 4.5M CPU: 17ms CGroup: /system.slice/isc-dhcp-server.service └─5781 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf ens33 Elb 27 18:25:42 dhcp.itnixpro.com dhcpd[5781]: For info, please visit https://www.isc.org/software/dhcp/ Elb 27 18:25:42 dhcp.itnixpro.com dhcpd[5781]: Wrote 0 leases to leases file. Elb 27 18:25:42 dhcp.itnixpro.com sh[5781]: Wrote 0 leases to leases file. Elb 27 18:25:43 dhcp.itnixpro.com dhcpd[5781]: Listening on LPF/ens33/08:00:27:40:84:d0/192.168.0.0/24 Elb 27 18:25:43 dhcp.itnixpro.com sh[5781]: Listening on LPF/ens33/08:00:27:40:84:d0/192.168.0.0/24 Elb 27 18:25:43 dhcp.itnixpro.com dhcpd[5781]: Sending on LPF/ens33/08:00:27:40:84:d0/192.168.0.0/24 Elb 27 18:25:43 dhcp.itnixpro.com sh[5781]: Sending on LPF/ens33/08:00:27:40:84:d0/192.168.0.0/24 Elb 27 18:25:43 dhcp.itnixpro.com dhcpd[5781]: Sending on Socket/fallback/fallback-net Elb 27 18:25:43 dhcp.itnixpro.com sh[5781]: Sending on Socket/fallback/fallback-net Elb 27 18:25:43 dhcp.itnixpro.com dhcpd[5781]: Server starting service.
- Also check the logs;
tail -f /var/log/dhcpd.log
- It’s a wrap! You have made it to the end of our article. Congrats! you have learned how to Install DHCP Server on Ubuntu 22.04.
Read more about DHCP protocol on the manpages.
You need to configure DHCP clients. Check the guide below;
How to Configure DHCP Client on Ubuntu 22.04
Other Tutorials
Install Xrdp server on Rocky Linux
Thanks, missed semicolon in
option domain-name “itnixpro.com” <—
Cheers,
S.