Share this page : facebooktwitterlinkedinmailfacebooktwitterlinkedinmail
The dhcp package contains an ISC DHCP server. First, install the package as the superuser:
~]# yum install dhcp
Installing the dhcp package creates a file, /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
The sample configuration file can be found at /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.
DHCP also uses the file /var/lib/dhcpd/dhcpd.leases to store the client lease database.

Configuration File

The first step in configuring a DHCP server is to create the configuration file that stores the network information for the clients. Use this file to declare options and global options for client systems.
The configuration file can contain extra tabs or blank lines for easier formatting. Keywords are case-insensitive and lines beginning with a hash mark (#) are considered comments.
There are two types of statements in the 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.
The parameters that start with the keyword option are reffered to as options. These options control DHCP options; whereas, parameters configure values that are not optional or control how the DHCP server behaves.
Parameters (including options) declared before a section enclosed in curly brackets ({ }) are considered global parameters. Global parameters apply to all the sections below it.
In Example 10.1, “Subnet Declaration”, the routers, subnet-mask, domain-search, domain-name-servers, and time-offset options are used for any host statements declared below it.
Additionally, a subnet can be declared, a subnet declaration must be included for every subnet in the network. If it is not, the DHCP server fails to start.
In this example, there are global options for every DHCP client in the subnet and a range declared. Clients are assigned an IP address within the range.
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

 

To configure a DHCP server that leases a dynamic IP address to a system within a subnet, modify Example “Range Parameter” with your values. It declares a default lease time, maximum lease time, and network configuration values for the clients. This example assigns IP addresses in the range 192.168.1.10 and 192.168.1.100 to client systems.
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

 

To assign an IP address to a client based on the MAC address of the network interface card, use the hardware ethernet parameter within a host declaration. As demonstrated in Example  “Static IP Address using DHCP”, the host apex declaration specifies that the network interface card with the MAC address 00:A0:78:8E:9E:AA always receives the IP address 192.168.1.4.
Note that the optional parameter host-name can also be used to assign a host name to the client.
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


All subnets that share the same physical network should be declared within a shared-network declaration as shown in Example  “Shared-network Declaration”. Parameters within the shared-network, but outside the enclosed subnet declarations, are considered to be global parameters. The name of the shared-network must be a descriptive title for the network, such as using the title ‘test-lab’ to describe all the subnets in a test lab environment.
shared-network name {
    option domain-search              "test.redhat.com";
    option domain-name-servers      ns1.redhat.com, ns2.redhat.com;
    option routers                  192.168.0.254;
    more parameters for EXAMPLE shared-network
    subnet 192.168.1.0 netmask 255.255.252.0 {
        parameters for subnet
        range 192.168.1.1 192.168.1.254;
    }
    subnet 192.168.2.0 netmask 255.255.252.0 {
        parameters for subnet
        range 192.168.2.1 192.168.2.254;
    }
}
Example . Shared-network Declaration
As demonstrated in Example, “Group Declaration”, the group declaration is used to apply global parameters to a group of declarations. For example, shared networks, subnets, and hosts can be grouped.
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:

[[email protected] ~]# 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.

[[email protected] dhcp]# systemctl restart dhcpd
[[email protected] 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-pid

May 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

Leave a Reply

Your email address will not be published.