Skip to main content
Engineering LibreTexts

10-D.5: DHCP Configuration

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

    DHCP Configuration

    DHCP is an abbreviation for Dynamic Host Configuration Protocol. It is an application layer protocol used by hosts for obtaining network setup information. DHCP across a network is controlled by a DHCP server that dynamically distributes network configuration parameters such as IP addresses, subnet mask and gateway address.

    To clarify what DHCP is about:

    • Dynamic – Means it works automatically
    • Host – Any computer that is connected to the network
    • Configuration – To configure a host means to provide network information(ip address,subnet mask,Gateway address) to a host
    • Protocol – Set of rules

    Disadvantage of Manually Configuring the Host

    Configuring a host when it is connected to the network can be done either manually i.e., by the network administrator or by the DHCP server. In case of home networks, manual configuration is quite easy, whereas in the large networks, the Network Administrator might face many problems. Also, the manual configuration is prone to mistakes. For example, a Network Administrator might assign an IP address which was already assigned. Thus, causing difficulty for both administrator as well as neighbors on the network.

    Configuring a Host Using DHCP

    To configure a host, we require the following things:

    • Leased IP address – IP address which is "leased" to a particular network device for a specific time frame which can be a few hours, few days or even few weeks.
    • Subnet Mask – This is determined by which subnet the host is on.
    • Gateway address – The Gateway is the Internet Service Provider that connects user to the internet. The Gateway address lets the host know where to send network packets that are being sent to an outside network.

    There are several DHCP entities that administrators need to be familiar with:

    • DHCP server: It automatically provides network information (IP address, subnet mask, gateway address) - this data is "leased" to the requesting host. Once the duration is expired, that network information can be assigned to another machine. It also keeps track of which IP addresses are assigned and who they are assigned to.
    • DHCP client: Any network device which requests an IP address lease is considered as DHCP client.
    • DHCP Relay Agent: In case we have only one DHCP server for multiple networks, this Agent forwards the DHCP request to the DHCP server. Using a DHCP Relay Agent allows the use of a single DHCP server to configure multiple LANs.

    The DHCP Lease and Renewal Process

    DHCP servers listen on port number 67 and the client listens on port 68. It is a Client/Server protocol which uses UDP services. IP address is assigned from a pool of addresses known to the server. In DHCP, the client and the server usually exchange four DHCP messages in order to make a connection, also called DORA process, but there are eight DHCP messages in the process.

    These messages are given as below:

    DHCP discover message – This is a first message in the communication process between server and client. This message is generated by the client in order to discover if there is any DHCP server present in a network. This message is broadcasted to all devices present in a network to find the DHCP server. This message is 342 or 576 bytes long.

    DHCP offer message – The server will respond to a host with this message specifying the unleased IP address and the other configuration information. This message is broadcasted by the server. The message is 342 bytes. If there are more than one DHCP servers present in the network the client will accept the first DHCP OFFER message it receives. There is a server ID specified in the DHCP OFFER packet in order for the client to identify which server it is dealing with.

    DHCP request message – When a client receives an offer message, it responds by broadcasting a DHCP request message. The client then sends ARP request in order to find out if there is any other host in the network with same IP address. If there is no reply then the client assumes there is no other client with same IP address in the network and the message is broadcasted to server showing the acceptance of the IP address.

    DHCP acknowledgement message – In response to the request message, the server will track the client ID and the assigned IP address and the lease time.

    DHCP negative acknowledgement message – Whenever a DHCP server receives a request for an IP address that is invalid according to the scopes that is configured with, it sends DHCP Nak message to client. For example, if the server has no IP unused addresses in its specified address pool, then this message is sent to client.

    DHCP decline – If the DHCP client determines the offered configuration parameters are different or invalid, it sends the DHCP server a decline message. If the client receives a reply to the ARP by a host the client sends DHCP decline message to the server showing the offered IP address is already in use.

    DHCP release – A DHCP client sends a DHCP release packet to the server telling the server to release IP address and cancel any remaining lease time.

    DHCP inform If a client address has obtained IP address manually then the client uses a DHCP inform to obtain other local configuration parameters, such as domain name. In reply to the dhcp inform message, DHCP server generates DHCP ack message with local configuration suitable for the client without allocating a new IP address. This DHCP ack message is unicast to the client.

    The /etc/dhcp/dhclient.conf File

    The dhclient.conf file contains configuration information for dhclient, the Internet Systems Consortium DHCP Client.

    The dhclient.conf file is a free-form ASCII text file. It is parsed by the recursive-descent parser built into dhclient. The file may contain extra tabs and newlines for formatting purposes. Keywords in the file are case-insensitive. Comments may be placed anywhere within the file (except within quotes). Comments begin with the # character and end at the end of the line.

    The dhclient.conf file can be used to configure the behavior of the client in a wide variety of ways: protocol timing, information requested from the server, information required of the server, defaults to use if the server does not provide certain information, values with which to override information provided by the server, or values to prepend or append to information provided by the server. The configuration file can also be pre-initialized with addresses to use on networks that don't have DHCP servers.

    Adapted from:
    "Dynamic Host Configuration Protocol (DHCP)" by saurabhsharma56, Geeks for Geeks is licensed under CC BY-SA 4.0
    "How DHCP server dynamically assigns IP address to a host?" by Brahmani Sai., Geeks for Geeks is licensed under CC BY-SA 4.0

    10-D.5: DHCP Configuration is shared under a CC BY-NC license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?