安装:

yum install dhcp -y

拷贝配置文件:默认没有配置文件

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

修改配置:

option domain-name "example.org"; # 自动补全的域名
option domain-name-servers ns1.example.org, ns2.example.org; # DNS服务地址

default-lease-time 86400; # 默认租期(秒)
max-lease-time 186400; # 最大租期

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.84 192.168.1.89; # 分配的地址范围
  option routers 192.168.199.1; # 网关
}

# 将MAC地址和IP地址绑定
host test {
  hardware ethernet 0:0:c0:5d:bd:95; # MAC地址
  fixed-address 192.168.1.89; # 要绑定的IP地址
}

启动服务:

systemctl start dhcpd.service

查看那些主机获取了地址:

cat /var/lib/dhcpd/dhcpd.leases

dhcp测试客户端:

dhclient -d
dhclient -d -s 192.168.1.10 # -s 指定服务器地址