~]# yum install dhcp
/etc/dhcp/dhcpd.conf
, which is merely an empty configuration file:~]# cat /etc/dhcp/dhcpd.conf
# # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.sample
/usr/share/doc/dhcp-<version>/dhcpd.conf.sample
. You should use this file to help you configure /etc/dhcp/dhcpd.conf
, which is explained in detail below./var/lib/dhcpd/dhcpd.leases
to store the client lease database.Configuration File
-
Parameters — State how to perform a task, whether to perform a task, or what network configuration options to send to the client.
-
Declarations — Describe the topology of the network, describe the clients, provide addresses for the clients, or apply a group of parameters to a group of declarations.
subnet 192.168.1.0 netmask 255.255.255.0 { option routers 192.168.1.254; option subnet-mask 255.255.255.0; option domain-search "example.com"; option domain-name-servers 192.168.1.1; option time-offset -18000; # Eastern Standard Time range 192.168.1.10 192.168.1.100; }
Example 1. Subnet Declaration
default-lease-time 600; max-lease-time 7200; option subnet-mask 255.255.255.0; option broadcast-address 192.168.1.255; option routers 192.168.1.254; option domain-name-servers 192.168.1.1, 192.168.1.2; option domain-search "example.com"; subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.10 192.168.1.100; }
Example . Range Parameter
host apex { option host-name "apex.example.com"; hardware ethernet 00:A0:78:8E:9E:AA; fixed-address 192.168.1.4; }
Example . Static IP Address using DHCP
group { option routers 192.168.1.254; option subnet-mask 255.255.255.0; option domain-search "example.com"; option domain-name-servers 192.168.1.1; option time-offset -18000; # Eastern Standard Time host apex { option host-name "apex.example.com"; hardware ethernet 00:A0:78:8E:9E:AA; fixed-address 192.168.1.4; } host raleigh { option host-name "raleigh.example.com"; hardware ethernet 00:A1:DD:74:C3:F2; fixed-address 192.168.1.6; } }
Example Group Declaration
Problems:
The dhcp service is not working as expected
Troubleshooting:
use the command systemctl status dhcpd to see the dhcpd’s current status and potential error or reason for the error:
[root@localhost ~]# systemctl status dhcpd
dhcpd.service – DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled)
Active: failed (Result: exit-code) since Mon 2016-05-23 22:53:58 AEST; 1s ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Process: 39302 ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd –no-pid (code=exited, status=1/FAILURE)
Main PID: 39302 (code=exited, status=1/FAILURE)May 23 22:53:58 localhost.localdomain dhcpd[39302]: /etc/dhcp/dhcpd.conf line 10: unknown option dhcp.domain-name-server
May 23 22:53:58 localhost.localdomain dhcpd[39302]: option domain-name-server 192.
May 23 22:53:58 localhost.localdomain dhcpd[39302]: ^
May 23 22:53:58 localhost.localdomain dhcpd[39302]: Configuration file errors encountered — exiting
May 23 22:53:58 localhost.localdomain dhcpd[39302]:
May 23 22:53:58 localhost.localdomain dhcpd[39302]: This version of ISC DHCP is based on the release available
May 23 22:53:58 localhost.localdomain dhcpd[39302]: on ftp.isc.org. Features have been added and other changes
May 23 22:53:58 localhost.localdomain dhcpd[39302]: have been made to the base software release in order to make
May 23 22:53:58 localhost.localdomain systemd[1]: dhcpd.service: main process exited, code=exited, status=1/FAILURE
May 23 22:53:58 localhost.localdomain systemd[1]: Unit dhcpd.service entered failed state.
The output tell me that the dhcp did not work for the miss configuration reason, and also told me that the error is in the line 10.
so edit the configuration file /etc/dhcp/dhcpd.conf , deleted the line 10. Then restart the dhcpd.
[root@localhost dhcp]# systemctl restart dhcpd
[root@localhost dhcp]# systemctl status dhcpd
dhcpd.service – DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled)
Active: active (running) since Mon 2016-05-23 22:58:14 AEST; 4s ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 39364 (dhcpd)
CGroup: /system.slice/dhcpd.service
└─39364 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd –no-pidMay 23 22:58:14 localhost.localdomain systemd[1]: Started DHCPv4 Server Daemon.
May 23 22:58:14 localhost.localdomain dhcpd[39364]: Internet Systems Consortium DHCP Server 4.2.7
May 23 22:58:14 localhost.localdomain dhcpd[39364]: Copyright 2004-2014 Internet Systems Consortium.
May 23 22:58:14 localhost.localdomain dhcpd[39364]: All rights reserved.
May 23 22:58:14 localhost.localdomain dhcpd[39364]: For info, please visit https://www.isc.org/software/dhcp/
May 23 22:58:14 localhost.localdomain dhcpd[39364]: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not speci…g file
May 23 22:58:14 localhost.localdomain dhcpd[39364]: Wrote 0 leases to leases file.
May 23 22:58:14 localhost.localdomain dhcpd[39364]: Listening on LPF/eno16777736/00:0c:29:16:d8:04/192.168.0.0/24
May 23 22:58:14 localhost.localdomain dhcpd[39364]: Sending on LPF/eno16777736/00:0c:29:16:d8:04/192.168.0.0/24
May 23 22:58:14 localhost.localdomain dhcpd[39364]: Sending on Socket/fallback/fallback-net
Hint: Some lines were ellipsized, use -l to show in full.
Now test on the client and the client can get the IP address via DHCP server.
Reference
http://www.firewall.cx/linux-knowledgebase-tutorials/system-and-network-services/849-linux-services-dhcp-server.html