210.1. DHCP configuration
210.1 DHCP configuration
Weight: 2
Description: Candidates should be able to configure a DHCP server. This objective includes setting default and per client options, adding static hosts and BOOTP hosts. Also included is configuring a DHCP relay agent and maintaining the DHCP server.
Key Knowledge Areas:
DHCP configuration files, terms and utilities
Subnet and dynamically-allocated range setup
Awareness of DHCPv6 and IPv6 Router Advertisements
Terms and Utilities:
dhcpd.conf
dhcpd.leases
DHCP Log messages in syslog or systemd journal
arp
dhcpd
radvd
radvd.conf
What is DHCP?
Dynamic Host Configuration Protocol (DHCP) is a network protocol that is used to enable host computers to be automatically assigned IP addresses and related network configurations from a server. DHCP reduce the need for a network administrator or a user to manually assign IP addresses to all network devices .
How DHCP works?
The following steps show how DHCP actually works:

Once a client (that is configured to use DHCP) and connected to a network boots up, it broadcats a DHCPDISCOVER packet to all the network. and attempts to find a DHCP server on the wire.
Router/ Switch forwards the DHCPDISCOVER to the proper DHCP Server(as configured).When the DHCP server receives the DHCPDISCOVER request packet, it replies with a DHCPOFFER packet.Based on the configuration of available addresses, the client hardware address and/or host name and the configuration of DHCP server software determines the appropriate address to assign to the machine which originated the request. The the address temprorary reserved for the client.
Then the client gets the DHCPOFFER packet, and it sends a DHCPREQUEST packet to the server showing it is ready to receive the network configuration information provided in the DHCPOFFER packet.
Finally, after the DHCP server receives the DHCPREQUEST packet from the client, it sends the DHCPACK packet showing that the client is now permitted to use the IP address assigned to it for (configured) period of time.
DHCP use udp port number 67 be default.
Implementing DHCP Server
DHCP packages (on the server side) are not typically installed by default in most distributions.
Packages can be:
dhcp
dhcp-server
isc-dhcp-server (older)
dhcp3-server (LPIC-2 Exam Objectivd)
dhcp4-server
We use ubuntu for demontration with two network card:
Lets serach for the package name in ubuntu and starts:
Now lets see where are configuration and other files:
based on our distribution and service manager which is used (SysV , Upstart, Systemd) DHCP service migh be started right after installation, but weather its started or stopped, its okey because it wont serve and DHCP requests from any interfaces, till we configure that, here in ubuntu we use systemd and its enabled but stoped right after DHCP server installation:
Lets configure which interface our DHCP service listen on:
/etc/default/isc-dhcp-server
and set enterface like INTERFACE="ens38"
If your firewall is ON do not forget to configure it for DHCP service:
/etc/dhcpd.conf
The first step in configuring a DHCP server is to create the configuration file that stores the network information for the clients.
Primary location of DHCP configuration file can be found in /etc/dhcpd.conf (CentOS) or in /etc/dhcp/dhcp.conf (ubuntu)also is can be copied from /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example in (CentOS) or /usr/share/doc/isc-dhcp-server/examples/dhcpd.conf.example(ubuntu) directory.
The configuration file can contain extra tabs or blank lines for easier formatting. Keywords are case-insensitive and lines beginning with a hash sign (#) are considered comments.
Lets get into main configuration file:
there are two types of statements defined in the DHCP configuration file, these are:
parameters state how to carry out a task, whether to perform a task, or what network configuration options to send to the DHCP client.
declarations specify the network topology, define the clients, offer addresses for the clients, or apply a group of parameters to a group of declarations.
The parameters that start with the keyword option are referred to as options. These options control DHCP options; whereas, parameters configure values that are not optional or control how the DHCP server behaves.
Some of the most important options and directives are:
DNS Dynamic Updates
Determine whether you want the DHCP server to attempt to update the requesting clients DNS server addresses or not.
ddns-update-style [style];
ignore client-updates;
valid values are:
none : no attempt to update DNS servers is made
ad-hoc : oldest method, it is retired method of updating based on a script value(valid for DHCP3).
interim : C language based update of DNS, (named "interim" as such as it was intended as temporary replacement of "ad-hoc" method)
standard : newset method (DHCP v4), incorporates new standards for Dynamic DNS Services.
okey for now we do not configure Dynamic updates so lets continue.
IP Ranges:
subnet [network] netmask [mask] {[options and directives]}
defines and identifies a network IP and associated netmask as the network our server will maintain
Key Directives
Description
option routers "192.168.1.2"
define default GW for clients
option subnet-mask "255.255.255.0"
subnet mask of clients which are going to receive an IP addr
range 10.10.1.1 10.10.1.10
Define range of IP addr to release
option domain-name "example.com";
Domain name which our clients belong to
option domain-name-servers 8.8.8.8;
Define DNS server IP address or HostName
The ISC server allows the network architect to specify a default lease length, a minimum lease length, and a maximum lease length.
min-lease-time 400;
The minimum lease length is used to force the client to take a longer lease than it has requested.
default-lease-time 600;
The default lease length is used if the client does not request a specific lease.
max-lease-time 7200;
The maximum lease length defines the longest lease that the server can allocate.
for defining IP range:
Do not forget to restart DHCP service in order to changes take effect.
and also lets configure IP range by copying and modifying examples like this:
Okey after doing some modifications on configuration file , lets check it :
and if there is no errors restart the service :
and as you can see Wrote 0 leases to leases file !! oh lets bring up our client (server3) and see what will happen:
to make sure which DHCP server has issued our address, we can check it on the DHCP client :
DHCP Logging
Logs are in one of these two places depends on our distrobutions:
/var/log/messages
/var/log/daemon.log
and see the logs in server side:
ahun One IP address is released. Congratulations :).
/var/lib/dhcp/dhcp/leases
to see the leased IP adresses from our DHCP server:
Assign Static IP to DHCP Client
Some times we need to assign a specific IP address to a specific client, this way that client would get the same IP address even if it leaves our network and return.This way we can configure firewall rules in our network easily and add one level of security.
For accomplish our goal we need to simply define the section below in /etc/dhcp/dhcpd.conf file, where we must explicitly specify client’s MAC addresses and the fixed IP to be assigned.
host [name] { [static network information] }
key directives
description
hardware ether 00:0c:29:9f:ee:a3;
define mac address of client
fixed-address 192.168.1.110;
reserved IP address
option host-name "server3";
Client host name if u like to define
Lets go back and see released on the server:
Now we want to assign another IP address to the DHCP client called "server3", with the mac address of "00:0c:29:9f:ee:a3". Lets double check our information:
and add following section right after subnet section which we previously defined in /etc/dhcp/dhcpd.conf in DHCP server:
okey lets restart DHCP service:
and to check the result on DHCP client:
and on the server side:
and seems every thing is working properly.
DHCP relay agent
One of the main golas of Network Subnetting is reducing Network traffic by controlling Network broadcasts. But there is problem here, The process of DHCP DISCOVERY use broadcasts. So if we have a network with different subnets and routers we should know that our routers do not allow BROADCASTS deliver from one subnet to another one include DHCP DISCOVERY process.
One solution is running a DHCP server for each subnet and clients which are beside the routers , but it doesn't sound good. The right solution is using DHCP relay agent.
DHCP Relay Agent is a special agent that can listen on a subnet that do not have a DHCP Server for DHCP requests (or BOOTP) and then forward those on to a specific DHCP sever on another network.

DHCP Relay is like a piece of software which can be run on Network switches/ routers or can be installed and modified on a linux machine.
For demonstration we imaging new Centos Client with ip range 172.20.10.0/24 has come and ask for ip address, for that we configure DHCP relay agent on ubuntu as "server2". We use our previously configured DHCP Server ubuntu "server1" .
Our Relay:
And our poor client is waiting to receive an IP address from Rage Address 172:
Okey Lets start With DHCP Server and add bellow range to /etc/dhcp/dhcpd.conf :
and add the route on it:
okey Lets go and install DHCP relay Agent on ubuntu "server2":
and during installation it ask for DHCP server IP address and the interface which DHCP Relay Agent should listen on. For later modifying we should configure /etc/default/isc-dhcp-relay :
do not forget to restart isc-dhcp-relay service after any configuration.:
the comand to run agent is dhcrelay [IP of DHCP Server to Forward to] :
and Finally lets check our "CentOS7" DHCP Client machine:
and you can go and see more logs on "server1" our main DHCP server :)
Configuring DHCP on client Machine
There are always some clients which we have manually set the IP address on them. If we want these clients use our DHCP server we have to modify interface configuration file so based on our distro:
in cent os /etc/sysconfig/network-scripts/ifcfg-eth0 should be like this :
and in ubuntu /etc/network/interfaces should be modified like this:
DHCP FOR IPV6 (DHCPV6)
The ISC DHCP includes support for IPv6 (DHCPv6) since the 4.x release with a DHCPv6 server, client and relay agent functionality. The server, client and relay agents support both IPv4 and IPv6. However, the client and the server can only manage one protocol at a time . for dual support they must be started separately for IPv4 and IPv6.
The DHCPv6 server configuration file is installed together with the dhcp package and it can be found at /etc/dhcp/dhcpd6.conf.
The sample server configuration file can be found at /usr/share/doc/dhcp-<version>/dhcpd6.conf.sample . Like what we have in IPv4.
A simple DHCPv6 server configuration file looks like this:
the DHCPv6 service is named "dhcpd6" which should be started and stopped as root.
DHCPv6 can be configured two modes to work in:
statefull : Stateless configuration (also known as SLAAC-StateLess AutoConfiguration) The stateful version of DHCPv6 is pretty much the same as for IPv4. Our DHCPv6 server will assign IPv6 addresses to all DHCPv6 clients and it will keep track of the bindings. In short, the DHCPv6 servers knows exactly what IPv6 address has been assigned to what host.
stateless : Stateless works a bit different. The DHCPv6 server does not assign IPv6 addresses to the DHCPv6 clients, this is done through "autoconfiguration." The DHCPv6 server is only used to assign information that autoconfiguration doesn’t….stuff like a domain-name, multiple DNS servers and all the other options that DHCP has to offer.
radvd
IPv6 has a lot more support for autoconfiguration than IPv4. But for this autoconfiguration to work on the hosts of a network, the routers of the local network have to run a program which answers the autoconfiguration requests of the hosts.
On Linux this program is called radvd, which stands for Router ADVertisement Daemon. This daemon listens to router solicitations (RS) and answers with router advertisement (RA).
These RAs contain information, which is used by hosts to configure their interfaces. This information includes address prefixes, the MTU of the link and information about default routers.
Of course the routers can't autoconfigure themself, so the information on the routers has to be provided by the administrator of the system. This is done by manually configuring the interfaces and routes and by configuring the router advertisement daemon.
radvd.conf
Radvd's config file is normally /etc/radvd.conf. An simple example looks like following:
RADVD or DHCPv6
we need at least radvd. Router advertisements communicate to devices on the network what the default gateway is and what the network configuration is. we always need that.
The router advertisement can tell clients whether they are allowed to choose their own addresses or not (auto configuration). If we allow this then we might not need DHCP at all. Then we can add DHCP, either stateless or stateful.
As we need radvd anyway it's the easiest, possibly combined with stateless DHCP. Don't bother with stateful DHCP unless we really need to manage addresses manually.
Last updated