如何在 CentOS 7 上安装 DHCP 服务器

对于那些不知道的人, 动态主机配置协议 (DHCP) 是用于 Internet 协议 (IP) 网络的标准化网络协议,用于动态分配网络配置参数,例如接口和服务的 IP 地址。 使用 DHCP,计算机会自动从 DHCP 服务器请求 IP 地址和网络参数,从而减少网络管理员或用户手动配置这些设置的需要。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单。 我将向您展示如何在 CentOS 7 上逐步安装 DHCP 服务器。

在 CentOS 7 上安装 DHCP 服务器

步骤 1. 首先,确保所有软件包都是最新的。

yum -y update

步骤 2. 安装 DHCP 服务器。

要在 CentOS 7 上安装 DHCP 服务器,请输入以下命令:

yum install dhcp -y

步骤 3. 配置 DHCP 服务器。

安装后,您需要编辑 dhcpf.conf,它是空白的。 对于我使用以下内容的基本设置,它应该可以帮助您工作。 请注意我的内网地址是172.16.1.0/24。 所以我在这个文件中的规范与它有关。 您将根据自己的网络放置信息:

$ nano /etc/dhcp/dhcpd.conf
####Our basic DHCP example configuration ####Our Domain option domain-name "idroot.us"; ####The DNS servers for name resolution option domain-name-servers 8.8.8.8; ####Our IP Lease time default-lease-time 600; max-lease-time 7200; ####Use this to enble / disable dynamic dns updates globally. ddns-update-style none; #### This DHCP server is the official DHCP server for the local network. authoritative; #### Use this to send dhcp log messages to a different log file (you also #### have to hack syslog.conf to complete the redirection). log-facility local7; #### Our Subnet, IP address Pool and gateway/router subnet 172.16.1.0 netmask 255.255.255.0 {  range dynamic-bootp 172.16.1.10 172.16.1.253;  option broadcast-address 172.16.1.255;  option routers 172.16.1.254; } #### Lets reserve an IP address for an internal machine #### make sure the IP used here is not defined in the IP POOL above host vip {  hardware ethernet 08:00:07:26:c0:a5;  fixed-address 172.16.1.5; }

最后,您必须使用以下命令重新启动 DHCP 服务:

systemctl start dhcpd.service && systemctl enable dhcpd.service

恭喜! 您已成功安装 DHCP 服务器。 感谢您使用本教程在 CentOS 7 系统上安装 DHCP 服务器。 如需其他帮助或有用信息,我们建议您查看 CentOS 官方网站.