translated

This commit is contained in:
geekpi 2023-05-16 08:47:58 +08:00
parent 91e764ca2a
commit 1ab2744320
2 changed files with 131 additions and 115 deletions

View File

@ -1,115 +0,0 @@
[#]: subject: "How to Configure DHCP Server on RHEL 9 / Rocky Linux 9"
[#]: via: "https://www.linuxtechi.com/configure-dhcp-server-on-rhel-rockylinux/"
[#]: author: "Pradeep Kumar https://www.linuxtechi.com/author/pradeep/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to Configure DHCP Server on RHEL 9 / Rocky Linux 9
======
DHCP, an acronym for Dynamic Host Configuration Protocol, is a network protocol that auto-assigns IP addresses to client systems in a computer network. It assigns clients from a DHCP pool or range of IP addresses specified in its configuration. While you can manually assign a static IP to client systems, a DHCP server simplifies this and dynamically assigns IP addresses to the client systems on your network.
In this post, we will demonstrate how to install and configure DHCP Server on RHEL 9 / Rocky Linux 9
##### Prerequisites
- Pre-Installed RHEL 9 or Rocky Linux 9
- Regular User with sudo sdmin rights
- Locally Configured YUM/DNF Repo or Red Hat Subscription for RHEL 9
- Internet Connectivity
Without any further delay, lets jump into DHCP server installation steps.
### 1) Configure Static IP address on RHEL 9 / Rocky Linux 9
As you get started, its imperative to set a static IP address on your RHEL or Rocky Linux system. There are various ways of doing this, but the easiest and most intuitive one is using the nmtui or nmcli utility.
Read Also : How to Set Static IP Address on RHEL 9
To confirm the IP address of your linux system, run below ip command
```
$ ip a
```
### 2) Install and Configure DHCP Server
Once you have configured a static IP, the next course of action is to install a DHCP server. RHEL 9 or Rocky Linux 9 repositories (BaseOS) provide the dhcp-server package by default and you can install it as shown.
```
$ sudo dnf install dhcp-server -y
```
Post dhcp server installation, we need to go a step further and configure the settings. So, open the DHCP configuration file.
```
$ sudo vi /etc/dhcp/dhcpd.conf
```
Paste the following lines of code into the configuration file. Be sure to configure the subnet to your preferred values.
```
default-lease-time 3600;
max-lease-time 86400;
authoritative;
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200;
option routers 192.168.10.1;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.10.1;
}
```
Save & close the file.
Lets take a look at some of these values:
- The default-lease-time value specifies how long the DHCP server will lease an address to a client. In this case, the default-lease-time value is 3600 seconds or 1 hour. The max-lease-time is the maximum duration that the IP will be leased to a client. In our case, this is set to 86400 seconds or 24 hours.
- The next section is the subnet configuration. In this setup, 192.168.10.0, is the subnet and 255.255.255.0 is the subnet mask. The IP address range starts from 192.168.10.100 right through 192.168.10.200.
- The option router option defines the default gateway. In this case, 192.168.10.1.
- The option subnet-mask option determines the subnet-mask assignment to each client or host. In this case, 255.255.255.0.
- Lastly, domain-name-servers specifies the DNS servers. In this case 192.168.10.1.
Once done, save the changes and exit. Then enable and start the DHCP service.
```
$ sudo systemctl enable --now dhcpd
$ sudo systemctl status dhcpd
```
##### PLEASE NOTE
At this point, the DHCP service should be dishing out IP addresses. In case you have another DHCP server or router in your LAN, its prudent to turn it off to prevent a conflict of IP address assignment. This would lead to some clients getting the IP assignment from the RHEL or Rocky Linux server and the rest from the router which is certainly not what you want to happen.  So, remember to turn off any other DHCP server in your LAN setup.
### 3) Test DHCP Server installation
In our simulated LAN setup, you can see that Ubuntu system has already picked an IP from the RHEL or Rocky Linux DHCP server.
Head back to our dhcp server and search the Ubuntu machine ip address in /var/log/message file
```
$ sudo tail -50 /var/log/messages | grep -i 192.168.10.100
```
Perfect, output above confirms that Ubuntu machine got the IP server from our DHCP server.
##### Conclusion
This draws this post to a close. In this guide, you have learned how to install and configure the DHCP server on RHEL 9 / Rocky Linux 9. Kindly do post your queries and feedback in below comments section.
--------------------------------------------------------------------------------
via: https://www.linuxtechi.com/configure-dhcp-server-on-rhel-rockylinux/
作者:[Pradeep Kumar][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linuxtechi.com/author/pradeep/
[b]: https://github.com/lkxed/

View File

@ -0,0 +1,131 @@
[#]: subject: "How to Configure DHCP Server on RHEL 9 / Rocky Linux 9"
[#]: via: "https://www.linuxtechi.com/configure-dhcp-server-on-rhel-rockylinux/"
[#]: author: "Pradeep Kumar https://www.linuxtechi.com/author/pradeep/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
如何在 RHEL 9 / Rocky Linux 9 上配置 DHCP 服务器
======
DHCP 是动态主机配置协议的首字母缩写词,是一种网络协议,可自动为计算机网络中的客户端系统分配 IP 地址。它从 DHCP 池或在其配置中指定的 IP 地址范围分配客户端。虽然你可以手动为客户端系统分配静态 IP但 DHCP 服务器简化了这一过程,并为网络上的客户端系统动态分配 IP 地址。
在本文中,我们将演示如何在 RHEL 9 / Rocky Linux 9 上安装和配置 DHCP 服务器
##### 先决条件
- 预装 RHEL 9 或 Rocky Linux 9
- 具有 sudo sdmin 权限的普通用户
- 本地配置的 YUM/DNF 仓库或 RHEL 9 的 Red Hat 订阅
- 互联网连接
事不宜迟,让我们进入 DHCP 服务器安装步骤。
### 1) 在 RHEL 9 / Rocky Linux 9 上配置静态 IP 地址
开始时,必须在 RHEL 或 Rocky Linux 系统上设置静态 IP 地址。有多种方法可以执行此操作,但最简单和最直观的方法是使用 nmtui 或 nmcli 实用程序。
要确认你的 Linux 系统的 IP 地址,请运行以下 ip 命令:
```
$ ip a
```
![][1]
### 2) 安装和配置 DHCP 服务器
配置静态 IP 后,下一步就是安装 DHCP 服务器。RHEL 9 或 Rocky Linux 9 仓库 (BaseOS) 默认提供 dhcp-server 包,你可以如图所示安装它。
```
$ sudo dnf install dhcp-server -y
```
![][2]
安装 dhcp 服务器后,我们需要进一步并配置设置。因此,打开 DHCP 配置文件。
```
$ sudo vi /etc/dhcp/dhcpd.conf
```
将以下代码行粘贴到配置文件中。请务必将子网配置为你的首选值。
```
default-lease-time 3600;
max-lease-time 86400;
authoritative;
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200;
option routers 192.168.10.1;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.10.1;
}
```
保存并关闭文件。
![][3]
让我们看一下其中的一些值:
- default-lease-time 值指定 DHCP 服务器将地址租给客户端的时间。在这种情况下,默认租用时间值为 3600 秒或 1 小时。max-lease-time 是将 IP 租给客户端的最长持续时间。在我们的例子中,这被设置为 86400 秒或 24 小时。
- 下一部分是子网配置。在此设置中192.168.10.0 是子网255.255.255.0 是子网掩码。IP 地址范围从 192.168.10.100 一直到 192.168.10.200。
- option router 选项定义默认网关。在本例中为 192.168.10.1。
- option subnet-mask 选项确定分配给每个客户端或主机的子网掩码。在本例中为 255.255.255.0。
- 最后domain-name-servers 指定 DNS 服务器。在本例中为 192.168.10.1。
完成后,保存更改并退出。然后启用并启动 DHCP 服务。
```
$ sudo systemctl enable --now dhcpd
$ sudo systemctl status dhcpd
```
![][4]
##### 请注意
此时DHCP 服务应该分发 IP 地址。如果你的 LAN 中有另一个 DHCP 服务器或路由器,关闭它以防止 IP 地址分配冲突是明智的。这将导致一些客户端从 RHEL 或 Rocky Linux 服务器获得 IP 分配,而其余的则从路由器获得 IP 分配,这当然不是你想要发生的事情。因此,请记住关闭 LAN 设置中的任何其他 DHCP 服务器。
### 3) 测试 DHCP 服务器安装
在我们模拟的 LAN 设置中,你可以看到 Ubuntu 系统已经从 RHEL 或 Rocky Linux DHCP 服务器中选择了一个 IP。
![][5]
回到我们的 dhcp 服务器并在 /var/log/message 文件中搜索 Ubuntu 机器的 ip 地址:
```
$ sudo tail -50 /var/log/messages | grep -i 192.168.10.100
```
![][6]
完美,上面的输出确认 Ubuntu 机器从我们的 DHCP 服务器获得了 IP 服务器。
##### 结论
这篇文章到此结束。在本指南中,你学习了如何在 RHEL 9 / Rocky Linux 9 上安装和配置 DHCP 服务器。请在下面的评论部分发表你的疑问和反馈。
--------------------------------------------------------------------------------
via: https://www.linuxtechi.com/configure-dhcp-server-on-rhel-rockylinux/
作者:[Pradeep Kumar][a]
选题:[lkxed][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linuxtechi.com/author/pradeep/
[b]: https://github.com/lkxed/
[1]: https://www.linuxtechi.com/wp-content/uploads/2023/04/Confirm-IP-Address-RHEL-RockyLinux.png?ezimgfmt=ng:webp/ngcb22
[2]: https://www.linuxtechi.com/wp-content/uploads/2023/04/Install-DHCP-Server-DNF-Command.png?ezimgfmt=ng:webp/ngcb22
[3]: https://www.linuxtechi.com/wp-content/uploads/2023/04/DHCP-Conf-File-RHEL-RockyLinux.png?ezimgfmt=ng:webp/ngcb22
[4]: https://www.linuxtechi.com/wp-content/uploads/2023/04/DHCP-Server-Service-Status-RHEL-RockyLinux.png?ezimgfmt=ng:webp/ngcb22
[5]: https://www.linuxtechi.com/wp-content/uploads/2023/04/Automatic-Assign-DHCP-Server-RHEL-RockyLinux-1024x584.png?ezimgfmt=ng:webp/ngcb22
[6]: https://www.linuxtechi.com/wp-content/uploads/2023/04/DHCP-Server-Logs-RHEL-RockyLinux-1024x116.png?ezimgfmt=ng:webp/ngcb22