1、安装软件 yum install -y dhcp
2、查看包相关信息 rpm -ql dhcp
主配置文件 /etc/dhcp/dhcpd.conf
系统服务 /usr/lib/systemd/system/dhcpd.service
示例配置文件 /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
租约文件 /var/lib/dhcpd/dhcpd.leases
3、提供配置文件
\cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
提示:使用全路径或\cp,脚本中常用,如果有同名文件直接覆盖
4、配置示例
配置一个192.168.122.0网段DHCP服务器
dns:114.114.114.114
range:192.168.122.100-200
gateway:192.168.122.1
vim /etc/dhcp/dhcpd.conf
option domain-name “up.com”;
option domain-name-servers 114.114.114.114;
default-lease-time 43200;
max-lease-time 86400;
log-facility local7;
# DHCP server to understand the network topology.
subnet 192.168.122.0 netmask 255.255.255.0 {
range 192.168.122.100 192.168.122.200;
option routers 192.168.122.1;
}
启动服务:systemctl start dhcpd
开机自启:systemctl enable dhcpd
检查:
状态:systemctl status dhcpd
进程:ps -ef | grep dhcpd
端口:netstat -an | grep “:67”
lsof -i :67
客户端测试:
windows客户端测试
ipconfig /release 释放
ipconfig /renew 重新获取
ipconfig /flushdns 清除dns缓存
Linux客户端测试:
临时测试:dhclient
nmcli con modify ens33 ipv4.method auto