Discover the step-by-step process to setup DHCP Server in Linux 9 effortlessly. Empower your network infrastructure with dynamic IP address allocation, streamlining device connectivity and management. #centlinux #linux #dhcp
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 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 administration 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.
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:
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.
We are using a minimal installed Rocky Linux 9 operating system with following specifications.
Login to your Rocky Linux server as root user by using a ssh client.
Execute following command to update software packages in your Linux operating system.
# dnf update -y
If above command updates a software package related to your Linux kernel, then you should reboot your Linux server with new Kernel.
# reboot
Note down the versions of Linux Kernel and Rocky Linux operating system, that are being used in this tutorial.
# uname -r 5.14.0-162.23.1.el9_1.x86_64 # cat /etc/rocky-release Rocky Linux release 9.1 (Blue Onyx)
Bash Completion is a very handy software for auto-completion of Linux commands, especially for nmcli command.
Therefore, you should install bash-completion before configuring your DHCP server.
# dnf install -y bash-completion # source /etc/profile.d/bash_completion.sh
Check status of your current network connection.
# ip -4 a 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.2
Reload your network connection to apply changes.
# nmcli c down ens160 ; nmcli c up ens160
Now, again check the status of your network connection.
# ip -4 a 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/hosts
You can install Linux based DHCP server i.e. dhcpd by using dnf command.
# dnf install -y dhcp-server
Edit dhcpd configuration file by using vim text editor.
# vi /etc/dhcp/dhcpd.conf
The 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.service
You need to allow dhcp service in Linux firewall to receive DHCP client requests.
# firewall-cmd --permanent --add-service=dhcp success # firewall-cmd --reload success
Mastering to setup DHCP Server in 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. If you are new to Linux command-line then we suggest that you should attend online training: Linux command line for beginners
Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…
Discover how to change Apache port in Linux easily. Follow our simple guide to modify…
Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…
Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…
Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…
Explore the ultimate guide to VPS servers and learn everything about Virtual Private Servers, including…
This website uses cookies.