实验环境:RHEL7.4最小化安装
拓扑图:
[root@Yang ~]# yum install dhcp -y
[root@Yang ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y --生成配置文件
[root@Yang ~]# vim /etc/dhcp/dhcpd.conf ---写入下面内容
subnet 192.168.127.0 netmask 255.255.255.0 {
range 192.168.127.160 192.168.127.170;
option domain-name-servers 192.168.127.2;
option domain-name 'Yang dhcp server';
option routers 192.168.127.2;
option broadcast-address 192.168.127.254;
default-lease-time 600;
max-lease-time 7200;
}
[root@Yang ~]# systemctl start dhcpd ---启动服务
[root@Yang ~]# systemctl status dhcpd ---查看服务状态
● dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2018-02-05 07:21:33 EST; 1min 1s ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 1548 (dhcpd)
Status: 'Dispatching packets...'
CGroup: /system.slice/dhcpd.service
└─1548 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
Feb 05 07:21:33 Yang dhcpd[1548]: No subnet declaration for ens38 (no IPv4 addresses).
Feb 05 07:21:33 Yang dhcpd[1548]: ** Ignoring requests on ens38. If this is not what
Feb 05 07:21:33 Yang dhcpd[1548]: you want, please write a subnet declaration
Feb 05 07:21:33 Yang dhcpd[1548]: in your dhcpd.conf file for the network segment
Feb 05 07:21:33 Yang dhcpd[1548]: to which interface ens38 is attached. **
Feb 05 07:21:33 Yang dhcpd[1548]:
Feb 05 07:21:33 Yang dhcpd[1548]: Listening on LPF/ens33/00:0c:29:94:69:9c/192.168.127.0/24
Feb 05 07:21:33 Yang dhcpd[1548]: Sending on LPF/ens33/00:0c:29:94:69:9c/192.168.127.0/24
Feb 05 07:21:33 Yang dhcpd[1548]: Sending on Socket/fallback/fallback-net
Feb 05 07:21:33 Yang systemd[1]: Started DHCPv4 Server Daemon.
此时服务端配置成功
客户端口设置为dhcp,并重新启动网络服务就可以获取到分配的IP,如下图所示