Discover the step-by-step process to setup DHCP Server in Rocky Linux 9 effortlessly. Empower your network infrastructure with dynamic IP address allocation, streamlining device connectivity and management. #centlinux #linux #dhcp
Table of Contents
What is DHCP Server?
DHCP (Dynamic Host Configuration Protocol) server is a network server that automatically assigns IP addresses, subnet masks, default gateways, and other network parameters to client devices on a network.
When a client device connects to a computer network that is configured to use DHCP, it sends a broadcast request to the network requesting an IP address. The DHCP server responds to the request by assigning an IP address and other network settings to the client device. This allows the client device to communicate with other devices on the network and access the internet.
DHCP simplifies network management by eliminating the need for network administrators to manually assign IP addresses to client devices. It also allows for easier management of IP address assignments and reduces the risk of conflicting IP addresses on the network.

Read Also: A Comprehensive guide to Linux Networking
How does a DHCP server Work?
A DHCP (Dynamic Host Configuration Protocol) server works by dynamically assigning IP addresses and other network configuration parameters to devices on a network. Here’s how it typically operates:
- Client Request: When a device (a client) connects to a network, it initially does not have an IP address or other network configuration settings. It sends out a broadcast message called a DHCPDISCOVER message to discover DHCP servers available on the network.
- DHCP Offer: DHCP servers on the network receive the DHCPDISCOVER message and respond with a DHCPOFFER message. This message contains an available IP address and other network configuration parameters, such as subnet mask, default gateway, DNS servers, and lease duration.
- Client Request Acceptance: The client receives one or more DHCPOFFER messages from different DHCP servers and selects one offer to accept. It sends a DHCPREQUEST message to the chosen DHCP server, indicating its acceptance of the offered configuration.
- Assignment and Acknowledgment: The DHCP server that received the DHCPREQUEST message acknowledges the client’s request by sending a DHCPACK message. This message confirms the assignment of the IP address and other configuration parameters to the client.
- Configuration Renewal: The client uses the assigned IP address and network configuration parameters to communicate on the network. Periodically, it will attempt to renew its lease on the IP address by sending a DHCPREQUEST message to the DHCP server. If the DHCP server agrees to renew the lease, it responds with a DHCPACK message, extending the lease duration. If the lease expires without renewal, the IP address is returned to the pool of available addresses for reassignment.
Overall, DHCP simplifies network administration by automating the process of IP address allocation and configuration, allowing for efficient management of IP addresses and network resources. It is commonly used in both small and large networks to streamline device connectivity and maintenance.
Hisense 65″ E6 Cinema Series QLED 4K UHD Smart Fire TV (65E6QF, 2025 Model) – QLED, AI Light Sensor, Dolby Vision · Atmos, Voice Remote with Alexa, Motion Rate 120, HDR 10+ Adaptive, Game Mode Plus
27% OffEnvironment Specification
We are working with a minimal installation of the Rocky Linux 9 operating system, featuring the following specifications and configuration.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – Rocky Linux release 9.1 (Blue Onyx)
- Hostname – dhcp-01.centlinux.com
- IP Address – 192.168.116.128/24
For experimenting with a Linux server such as setting up a DHCP server on Rocky Linux 9, using a dedicated machine like a Mini PC or a reliable VPS can greatly enhance your learning and testing experience. A Mini PC offers a compact, low-power, and always-on environment ideal for hands-on server setups at home. [Buy our recommended Mini PC from Amazon]
While a VPS from providers like Hostinger provides easy scalability and remote access without any hardware maintenance. Both options are excellent for running a Rocky Linux server environment to safely test configurations and deployments without impacting your primary system. [Order Now and Avail Huge Discounts on Hostinger VPS]
Disclaimer: This post contains affiliate links. If you purchase a Mini PC or VPS through these links, I may earn a small commission at no extra cost to you. Your support helps me create more helpful Linux tutorials and content.
Updating Software Packages
Log in to your Rocky Linux server as the root user using an SSH client. Once logged in, execute the following command to ensure your system’s software packages are up to date with the latest security patches and improvements.
dnf update -yIf above command updates a software package related to your Linux kernel, then you should reboot your Linux server with new Kernel.
rebootMake sure to note down the versions of both the Linux Kernel and the Rocky Linux operating system that are being used in this tutorial. This information will be important for reference and ensuring compatibility with the steps and configurations outlined.
uname -r
cat /etc/rocky-releaseOutput:
5.14.0-162.23.1.el9_1.x86_64
Rocky Linux release 9.1 (Blue Onyx)
Bash Completion is an extremely useful tool that enables auto-completion for Linux commands, making it especially beneficial when working with commands like nmcli. This feature enhances productivity by reducing typing errors and speeding up command execution. As a result, it is highly recommended to install bash-completion before proceeding with the configuration of your DHCP server.
dnf install -y bash-completion
source /etc/profile.d/bash_completion.shSet Static IP Address
Check status of your current network connection.
ip -4 aOutput:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
altname enp3s0
inet 192.168.116.128/24 brd 192.168.116.255 scope global dynamic noprefixroute ens160
valid_lft 1676sec preferred_lft 1676sec
We are working on a virtual machine and the integrated DHCP server of the VMware host is assigning a dynamic IP address to our guest machine.
You need to set a static IP Address for your DHCP server. You can use following nmcli command to set IP Address, Gateway and DNS for your network connection.
nmcli c m ens160 ipv4.method manual ipv4.addresses 192.168.116.5/24 ipv4.gateway 192.168.116.2 ipv4.dns 192.168.116.2Reload your network connection to apply changes.
nmcli c down ens160 ; nmcli c up ens160Now, again check the status of your network connection.
ip -4 aOutput:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
altname enp3s0
inet 192.168.116.5/24 brd 192.168.116.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
Set Hostname & Local DNS resolution by executing following commands at Linux terminal.
hostnamectl set-hostname dhcp-01.centlinux.com
echo 192.168.116.5 dhcp-01 dhcp-01.centlinux.com >> /etc/hostsNorelco Philips OneBlade Pro 360 Face + Body, Electric Shaver, Beard Trimmer and Body Groomer, with 360 Blade Technology, 14-Length Precision Comb, Body Kit, Soft Pouch, Model QP6542/70
16% OffInstall & Setup DHCP Server in Linux
You can install Linux based DHCP server i.e. dhcpd by using dnf command.
dnf install -y dhcp-serverEdit dhcpd configuration file by using vim text editor.
vi /etc/dhcp/dhcpd.confThe dhcpd configuration file is empty by default, however it provides a path to a sample configuration file for your reference.
Add following directives in this file.
default-lease-time 900;
max-lease-time 10800;
authoritative;
subnet 192.168.116.0 netmask 255.255.255.0 {
range 192.168.116.50 192.168.116.200;
option routers 192.168.116.2;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.116.2;
}The above directives are quiet enough to create a production grade DHCP server.
Feel free to adjust above parameters according to your environment.
Enable and start dhcpd service.
systemctl enable --now dhcpd.serviceYou need to allow dhcp service in Linux firewall to receive DHCP client requests.
firewall-cmd --permanent --add-service=dhcp
firewall-cmd --reloadVideo Tutorial
Final Thoughts
Mastering to setup DHCP Server in Rocky Linux 9, opens up a realm of possibilities for network management. By dynamically allocating IP addresses, you streamline connectivity and simplify device management, enhancing the efficiency and scalability of your network infrastructure.
Your Linux servers deserve expert care! I provide reliable management and optimization services tailored to your needs. Discover how I can help!
If you’re serious about leveling up your Linux skills, I highly recommend the Linux Mastery: Master the Linux Command Line in 11.5 Hours by Ziyad Yehia course. It’s a practical, beginner-friendly program that takes you from the basics to advanced command line usage with clear explanations and hands-on exercises. Whether you’re a student, sysadmin, or developer, this course will help you build the confidence to navigate Linux like a pro.
👉 Enroll now through my affiliate link and start mastering the Linux command line today!
Disclaimer: This post contains affiliate links. If you purchase through these links, I may earn a small commission at no extra cost to you, which helps support this blog.
FAQs
1. Can I set up multiple DHCP scopes on Rocky Linux 9?
Yes, you can configure multiple DHCP scopes on Rocky Linux 9 by defining separate subnet declarations in the DHCP server configuration file. This allows the DHCP server to assign IP addresses dynamically within different network segments.
2. How do I reserve a specific IP address for a device in DHCP?
You can reserve an IP address for a device by creating a DHCP reservation using the device’s MAC address in the server configuration. This ensures the device always receives the same IP address from the DHCP server.
3. Is it possible to limit DHCP lease times dynamically?
Yes, lease times can be configured globally or per subnet in the DHCP server settings, allowing flexible control over how long an IP address is assigned before renewal is required.
4. How can I secure my DHCP server from unauthorized access?
You can enhance security by limiting DHCP responses to specific network interfaces, enabling firewall rules, and monitoring DHCP logs to detect suspicious activity on Rocky Linux 9.
5. What happens if two DHCP servers run on the same network?
Running two DHCP servers on the same network without coordination can lead to IP conflicts and network issues. It’s best to either disable one DHCP server or configure them carefully to serve distinct IP ranges.


Leave a Reply
Please log in to post a comment.