The Wayback Machine - https://web.archive.org/web/20240921025634/https://www.geeksforgeeks.org/dynamic-host-configuration-protocol-dhcp/
Open In App

Dynamic Host Configuration Protocol (DHCP)

Last Updated : 01 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Dynamic Host Configuration Protocol is a network protocol used to automate the process of assigning IP addresses and other network configuration parameters to devices (such as computers, smartphones, and printers) on a network. Instead of manually configuring each device with an IP address, DHCP allows devices to connect to a network and receive all necessary network information, like IP address, subnet mask, default gateway, and DNS server addresses, automatically from a DHCP server.

This makes it easier to manage and maintain large networks, ensuring devices can communicate effectively without conflicts in their network settings. DHCP plays a crucial role in modern networks by simplifying the process of connecting devices and managing network resources efficiently.

What is DHCP?

DHCP stands for Dynamic Host Configuration Protocol. It is the critical feature on which the users of an enterprise network communicate. DHCP helps enterprises to smoothly manage the allocation of IP addresses to the end-user clients’ devices such as desktops, laptops, cellphones, etc. is an application layer protocol that is used to provide:

Subnet Mask (Option 1 - e.g., 255.255.255.0)
Router Address (Option 3 - e.g., 192.168.1.1)
DNS Address (Option 6 - e.g., 8.8.8.8)
Vendor Class Identifier (Option 43 - e.g.,
'unifi' = 192.168.1.9 ##where unifi = controller)

DHCP is based on a client-server model and based on discovery, offer, request, and ACK. 

Why Do We Use DHCP?

DHCP helps in managing the entire process automatically and centrally. DHCP helps in maintaining a unique IP Address for a host using the server. DHCP servers maintain information on TCP/IP configuration and provide configuration of address to DHCP-enabled clients in the form of a lease offer.

Components of DHCP

The main components of DHCP include:

  • DHCP Server: DHCP Server is a server that holds IP Addresses and other information related to configuration.
  • DHCP Client: It is a device that receives configuration information from the server. It can be a mobile, laptop, computer, or any other electronic device that requires a connection.
  • DHCP Relay: DHCP relays basically work as a communication channel between DHCP Client and Server. 
  • IP Address Pool: It is the pool or container of IP Addresses possessed by the DHCP Server. It has a range of addresses that can be allocated to devices.
  • Subnets: Subnets are smaller portions of the IP network partitioned to keep networks under control. 
  • Lease: It is simply the time that how long the information received from the server is valid, in case of expiration of the lease, the tenant must have to re-assign the lease.
  • DNS Servers: DHCP servers can also provide DNS (Domain Name System) server information to DHCP clients, allowing them to resolve domain names to IP addresses.
  • Default Gateway: DHCP servers can also provide information about the default gateway, which is the device that packets are sent to when the destination is outside the local network.
  • Options: DHCP servers can provide additional configuration options to clients, such as the subnet mask, domain name, and time server information.
  • Renewal: DHCP clients can request to renew their lease before it expires to ensure that they continue to have a valid IP address and configuration information.
  • Failover: DHCP servers can be configured for failover, where two servers work together to provide redundancy and ensure that clients can always obtain an IP address and configuration information, even if one server goes down.
  • Dynamic Updates: DHCP servers can also be configured to dynamically update DNS records with the IP address of DHCP clients, allowing for easier management of network resources.
  • Audit Logging: DHCP servers can keep audit logs of all DHCP transactions, providing administrators with visibility into which devices are using which IP addresses and when leases are being assigned or renewed.

DHCP Packet Format

DHCP Packet Format

DHCP Packet Format

                                   

  • Hardware Length: This is an 8-bit field defining the length of the physical address in bytes. e.g for Ethernet the value is 6.
  • Hop count: This is an 8-bit field defining the maximum number of hops the packet can travel.
  • Transaction ID: This is a 4-byte field carrying an integer. The transcation identification is  set by the client and is used to match a reply with the request. The server returns the same value in its reply.
  • Number of Seconds: This is a 16-bit field that indicates the number of seconds elapsed since the time the client started to boot.
  • Flag: This is a 16-bit field in which only the leftmost bit is used and the rest of the bit should be set to os. A leftmost bit specifies a forced broadcast reply from the server. If the reply were to be unicast to the client, the destination. IP address of the IP packet is the address assigned to the client.
  • Client IP Address: This is a 4-byte field that contains the client IP address . If the client does not have this information this field has a value of 0.
  • Your IP Address: This is a 4-byte field that contains the client IP address. It is filled by the server at the request of the client.
  • Server IP Address: This is a 4-byte field containing the server IP address. It is filled by the server in a reply message.
  • Gateway IP Address: This is a 4-byte field containing the IP address of a routers. IT is filled by the server in a reply message.
  • Client Hardware Address: This is the physical address of the client .Although the server can retrieve this address from the frame sent by the client it is more efficient if the address is supplied explicity by the client in the request message.
  • Server Name: This is a 64-byte field that is optionally filled by the server in a reply packet. It contains a null-terminated string consisting of the domain name of the server. If the server does not want to fill this filed with data, the server must fill it with all 0s.
  • Boot Filename: This is a 128-byte field that can be optionally filled by the server in a reply packet. It contains a null- terminated string consisting of the full pathname of the boot file. The client can use this path to retrieve other booting information. If the server does not want to fill this field with data, the server must fill it with all 0s.
  • Options: This is a 64-byte field with a dual purpose. IT can carry either additional information or some specific vendor information. The field is used only in a reply message. The server uses a number, called a magic cookie, in the format of an IP address with the value of 99.130.83.99. When the client finishes reading the message, it looks for this magic cookie. If present the next 60 bytes are options. 

Working of DHCP

DHCP works on the Application layer of the UDP Protocol. The main task of DHCP is to dynamically assigns IP Addresses to the Clients and allocate information on TCP/IP configuration to Clients. For more, you can refer to the Article Working of DHCP.

The DHCP port number for the server is 67 and for the client is 68. It is a client-server protocol that uses UDP services. An IP address is assigned from a pool of addresses. In DHCP, the client and the server exchange mainly 4 DHCP messages in order to make a connection, also called the DORA process, but there are 8 DHCP messages in the process.

Working of DHCP

Working of DHCP

The 8 DHCP Messages

1. DHCP Discover Message: This is the first message generated in the communication process between the server and the client. This message is generated by the Client host in order to discover if there is any DHCP server/servers are present in a network or not. This message is broadcasted to all devices present in a network to find the DHCP server. This message is 342 or 576 bytes long.

discover

DHCP Discover Message

As shown in the figure, the source MAC address (client PC) is 08002B2EAF2A, the destination MAC address(server) is FFFFFFFFFFFF, the source IP address is 0.0.0.0(because the PC has had no IP address till now) and the destination IP address is 255.255.255.255 (IP address used for broadcasting). As they discover message is broadcast to find out the DHCP server or servers in the network therefore broadcast IP address and MAC address is used.  

2. DHCP Offers A Message: The server will respond to the host in this message specifying the unleased IP address and other TCP configuration information. This message is broadcasted by the server. The size of the message is 342 bytes. If there is more than one DHCP server present in the network then the client host will accept the first DHCP OFFER message it receives. Also, a server ID is specified in the packet in order to identify the server.

offer-1

DHCP Offer Message

 

Now, for the offer message, the source IP address is 172.16.32.12 (server’s IP address in the example), the destination IP address is 255.255.255.255 (broadcast IP address), the source MAC address is 00AA00123456, the destination MAC address is 00:11:22:33:44:55 (client’s MAC address). Here, the offer message is broadcast by the DHCP server therefore destination IP address is the broadcast IP address and destination MAC address is 00:11:22:33:44:55 (client’s MAC address)and the source IP address is the server IP address and the MAC address is the server MAC address. 

Also, the server has provided the offered IP address 192.16.32.51 and a lease time of 72 hours(after this time the entry of the host will be erased from the server automatically). Also, the client identifier is the PC MAC address (08002B2EAF2A) for all the messages. 

3. DHCP Request Message: When a client receives an offer message, it responds by broadcasting a DHCP request message. The client will produce a  gratuitous ARP in order to find if there is any other host present in the network with the same IP address. If there is no reply from another host, then there is no host with the same TCP configuration in the network and the message is broadcasted to the server showing the acceptance of the IP address. A Client ID is also added to this message. 

request-1

DHCP Request Message

Now, the request message is broadcast by the client PC therefore source IP address is 0.0.0.0(as the client has no IP right now) and destination IP address is 255.255.255.255 (the broadcast IP address) and the source MAC address is 08002B2EAF2A (PC MAC address) and destination MAC address is FFFFFFFFFFFF. 

Note – This message is broadcast after the ARP request broadcast by the PC to find out whether any other host is not using that offered IP. If there is no reply, then the client host broadcast the DHCP request message for the server showing the acceptance of the IP address and Other TCP/IP Configuration. 

4. DHCP Acknowledgment Message: In response to the request message received, the server will make an entry with a specified client ID and bind the IP address offered with lease time. Now, the client will have the IP address provided by the server. 

acknowledgement

Now the server will make an entry of the client host with the offered IP address and lease time. This IP address will not be provided by the server to any other host. The destination MAC address is 00:11:22:33:44:55 (client’s MAC address) and the destination IP address is 255.255.255.255 and the source IP address is 172.16.32.12 and the source MAC address is 00AA00123456 (server MAC address).  

5. DHCP Negative Acknowledgment Message: Whenever a DHCP server receives a request for an IP address that is invalid according to the scopes that are configured, it sends a DHCP Nak message to the client. Eg-when the server has no IP address unused or the pool is empty, then this message is sent by the server to the client. 

6. DHCP Decline: If the DHCP client determines the offered configuration parameters are different or invalid, it sends a DHCP decline message to the server. When there is a reply to the gratuitous ARP by any host to the client, the client sends a DHCP decline message to the server showing the offered IP address is already in use. 

7. DHCP Release: A DHCP client sends a DHCP release packet to the server to release the IP address and cancel any remaining lease time. 

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

Note – All the messages can be unicast also by the DHCP relay agent if the server is present in a different network. 

Security Considerations for Using DHCP

To make sure your DHCP servers are safe, consider these DHCP security issues:

  • Limited IP Addresses: A DHCP server can only offer a set number of IP addresses. This means attackers could flood the server with requests, causing essential devices to lose their connection.
  • Fake DHCP Servers: Attackers might set up fake DHCP servers to give out fake IP addresses to devices on your network.
  • DNS Access: When users get an IP address from DHCP, they also get DNS server details. This could potentially allow them to access more data than they should. It’s important to restrict network access, use firewalls, and secure connections with VPNs to protect against this.

Protection Against DHCP Starvation Attack

A DHCP starvation attack happens when a hacker floods a DHCP server with requests for IP addresses. This overwhelms the server, making it unable to assign addresses to legitimate users. The hacker can then block access for authorized users and potentially set up a fake DHCP server to intercept and manipulate network traffic, which could lead to a man-in-the-middle attack.

Reasons Why Enterprises Must Automate DHCP?

Automating your DHCP system is crucial for businesses because it reduces the time and effort your IT team spends on manual tasks. For instance, DHCP-related issues like printers not connecting or subnets not working with the main network can be avoided automatically.

Automated DHCP also allows your operations to grow smoothly. Instead of hiring more staff to handle tasks that automation can manage, your team can focus on other important areas of business growth.

Advantages

  • Centralized management of IP addresses.
  • Centralized and automated TCP/IP configuration.
  • Ease of adding new clients to a network.
  • Reuse of IP addresses reduces the total number of IP addresses that are required.
  • The efficient handling of IP address changes for clients that must be updated frequently, such as those for portable devices that move to different locations on a wireless network.
  • Simple reconfiguration of the IP address space on the DHCP server without needing to reconfigure each client.
  • The DHCP protocol gives the network administrator a method to configure the network from a centralized area. 
  • With the help of DHCP, easy handling of new users and the reuse of IP addresses can be achieved.

Disadvantages

  • IP conflict can occur.
  • The problem with DHCP is that clients accept any server. Accordingly, when another server is in the vicinity, the client may connect with this server, and this server may possibly send invalid data to the client.
  • The client is not able to access the network in absence of a DHCP Server.
  • The name of the machine will not be changed in a case when a new IP Address is assigned.

Conclusion

In conclusion, DHCP is a technology that simplifies network setup by automatically assigning IP addresses and network configurations to devices. While DHCP offers convenience, it’s important to manage its security carefully. Issues such as IP address exhaustion, and potential data access through DNS settings highlight the need for robust security measures like firewalls and VPNs to protect networks from unauthorized access and disruptions. DHCP remains essential for efficiently managing network connections while ensuring security against potential risks.

Frequently Asked Questions on DHCP – FAQs

What are common issues with DHCP?

If the DHCP server is not properly set, it can cause difficulties such as IP address conflicts, incorrect subnet masks, incorrect default gateways, or insufficient IP address pools.

Which port is used in DHCP?

DHCP uses UDP port 67 on the server and UDP port 68 on the client.

Which layer protocol is DHCP?

DHCP is an application layer protocol.

Why is DHCP preferred?

It is a more efficient method for managing IP addresses than static address allocation. DHCP employs a stable transport layer protocol.



Previous Article
Next Article

Similar Reads

Dynamic Host Configuration Protocol (DHCP) vs Static IP Assignment
The two different approaches of network configuration to manage IP addresses for devices are DHCP (Dynamic Host Configuration Protocol) and Static IP Assignment which you can use to configure computer networks and to assign IP addresses to devices on a network are the focus. A distinctive feature of DHCP is the automated assignment of IP addresses
5 min read
Working of Dynamic Host Configuration Protocol
Dynamic Host Configuration Protocol (DHCP) is a network management protocol used in networks to dynamically assign IP addresses & other network configuration information like default gateway, mask, DNS server address etc. DHCP server automatically assigns IP address to various devices in network. This in turn reduces work of Network Administrat
3 min read
Introduction of Virtual Router Redundancy Protocol (VRRP) and its configuration
VRRP is an open standard protocol, which is used to provide redundancy in a network. It is a network layer protocol (protocol number-112). The number of routers (group members) in a group acts as a virtual logical router which will be the default gateway of all the local hosts. If one router goes down, one of the other group members can take place
4 min read
File transfer protocol server configuration using cisco packet tracer
In this article we are going to design a file transfer protocol server configuration in cisco packet tracer and checking the connectivity for uploading and downloading the file from remote PC. Objectives: To Configure FTP Services on Server.To Upload a File into the FTP Server from Remote PC.To Download a File from the FTP Server from Remote PC.Pro
3 min read
Hot Standby Router Protocol (HSRP) and Virtual Router Redundancy Protocol (VRRP)
Hot Standby Router Protocol (HSRP) is a CISCO proprietary protocol used to provide redundancy in a network. Only one router is the active router while others will be in standby state i.e the standby router will be responsible for forwarding the traffic when the active router fails. Virtual Router Redundancy Protocol (VRRP) is an open standard proto
3 min read
Cisco Discovery Protocol (CDP) and Link Layer Discovery Protocol (LLDP) in Data Link Layer
Layer 2 or the Datalink layer provides physical addressing and access to media. It defines how data is to be formatted for transmission and how access to the network is to be controlled. It also provides error detection, ensuring data on higher layers is formatted correctly for transmission. Cisco Discovery Protocol (CDP) and Link Layer Discovery P
2 min read
Difference between Stop and Wait protocol and Sliding Window protocol
Both the Stop and Wait protocol and the Sliding Window protocol are the techniques to the solution of flow control handling. The main difference between the Stop-and-wait protocol and the Sliding window protocol is that in the Stop-and-Wait Protocol, the sender sends one frame and waits for acknowledgment from the receiver whereas in the sliding wi
5 min read
Difference between Border Gateway Protocol (BGP) and Routing Information Protocol (RIP)
When dealing with network routing, it's crucial to understand the various protocols that help direct traffic across complex networks. Two significant protocols in this space are the Border Gateway Protocol (BGP) and the Routing Information Protocol (RIP). Each serves different purposes and operates under different principles. This article explores
5 min read
Difference between File Transfer Protocol (FTP) and Secure File Transfer Protocol (SFTP)
Data transfer is the most common task in network and system communications, and they involve transfer of files using two means i.e the File Transfer Protocol (FTP) and the Secure File Transfer Protocol (SFTP). FTP is a commonly applied protocol that enables files to be transferred through a network from one computer to another, but FTP is unsecure
5 min read
Difference between Spanning Tree Protocol (STP) and Rapid Spanning Tree Protocol (RSTP)
Spanning Tree Protocol (STP) and Rapid Spanning Tree Protocol (RSTP), are designed to avoid network loops in Ethernet. It provide loop-free logical topology. They were both designed to provide network reliability and particularly avoid broadcast radiation, but the major differences are on the rate, functionality and versatility. In this article we
5 min read
Difference between Serial Line Internet Protocol (SLIP) and Point-to-Point Protocol (PPP)
SLIP and PPP, which are the widely used serial connection techniques, help to connect the distant devices of the network. The fullform of SLIP is Session Layer Internetworking Protocol. SLIP being a primitive protocol put into use during the early connections to the Internet, when there was not much overhead. PPP is slightly more complex as the pro
6 min read
DHCP Relay Agent in Computer Network
Prerequisite - Dynamic Host Configuration Protocol (DHCP), How DHCP server dynamically assigns IP address to a host? To assign an IP address to the host dynamically, the DHCP client exchanges DHCP messages with the DHCP server in the DORA process. In the DORA process, the discover and request message is broadcast, the offer and the acknowledgement
6 min read
DHCP Snooping
Prerequisite - Dynamic Host Configuration Protocol (DHCP) Every protocol that we learn in Computer Network have some rules, these rules govern working of protocols. These rules sometimes provide way for attackers to take advantage of network. Attackers can also use working of DHCP to compromise our network. In this article we’ll learn how our netwo
3 min read
How to Configure DHCP Server on a Cisco Router?
In this article, we will discuss the overview of DHCP and will focus to implement How to Configure DHCP Server on a Cisco Router step by step. Let's discuss it one by one. Overview :DHCP (Dynamic Host Configuration Protocol) configuration is performed on routers to assign an IP address, subnet mask, gateway address ad DNS server address to the host
3 min read
Setting IP Address Using DHCP Server
Every computer on the network has to have an IP address for communication purposes. An IP address is an identifier for a computer or device on a network. The IP address can be assigned in two ways i.e. Static IP or Dynamic IP. Static IP: A static IP is where a user assigns an IP address manually. It has certain drawbacks for example you have 100 co
5 min read
DHCP Full Form
DHCP stands for Dynamic Host Configuration Protocol. It is the critical feature on which the users of an enterprise network communicate. DHCP helps enterprises to smoothly manage the allocation of IP addresses to the end-user clients' devices such as desktops, laptops, cellphones, etc.  Why Use DHCP?It is used because it automates the process of as
4 min read
Difference between BOOTP and DHCP
BOOTP stands for Bootstrap Protocol and DHCP stands for Dynamic Host Configuration Protocol. These protocols square measure used for getting the information science address of the host alongside the bootstrap info. The operation of each protocol is totally different in some manner. Dynamic host configuration protocol is also the extended version of
5 min read
Difference between DNS and DHCP
DNS and DHCP are two very critical services over a network. DNS refers to the Domain Name System, whereas DHCP refers to the Dynamic Host Configuration Protocol; these are two different but complementary services in the management of communication across a network. Whereas DNS works by translating human-readable domain names into the IP addresses t
4 min read
Dynamic Trunking Protocol (DTP)
Trunk ports are ports that are used to carry the traffic of more than one VLAN. The port which connects two different switches and the switches have more than one VLAN configured then that port should be made trunk. If all the VLANs are allowed then trunk ports will carry traffic of all the VLANs including native VLANs for which the traffic goes un
4 min read
Host Data Safeguarding
Hosts include clients and servers that send or receive data or services. It is essential to protect host data because an organization can lose data if cyber criminals steal it or device fails. Few methods to protect host data are given below: Encryption: Encryption changes data using a complicated algorithm to make it unreadable. A special key retu
2 min read
How to Calculate Number of Host in a Subnet?
In computer networks, an IP address is a unique address that identifies a device on the internet or a local network. Using IP address we can find information about the Class of IP address and number of computers connected in that network (range of IP address in that network), network IP address, broadcast address. Steps to find the number of comput
5 min read
Difference Between Host and Guest Operating System
An Operating System (OS) can be defined as a mediator, which works between the software & hardware of a computer The common task of OS includes memory management, managing different resources, device management, file handling, and others. Examples of some popular OS are Linux, MacOS, and Windows. In this article, we will see the difference betw
6 min read
What is Local Host?
When you call an IP address on your computer, you try to contact another computer on the internet, but when you call the IP address 127.0.0.1, you are communicating with the local host. Localhost is always your computer. Your computer is talking to itself when you call the local host. Your computer does not always directly identify the local host.
9 min read
What is "Network ID" and "Host ID" in IP Addresses?
Initially in 1980 IP address was divided into two fixed parts NID=8 bit and HID=24 bit. NID (Network ID) represents the entire network for a specified host. HID (Host ID) represents a specified user IP address within the network. So there are only 28 i.e., 256 networks are available and there are 224 i.e., 16M hosts per network. If even a small org
5 min read
Introduction to Host Names
A hostname is essentially a shorthand for a computer or other device attached to a computer network with a unique IP address, which is the physical address of the web server. Computers require names to distinguish one machine from another, just as a name is used to identify a person, a place, or a thing. Working of Host Name: Users typically do not
3 min read
Configuration of Router on a stick
Prerequisite - Access and trunk ports Switches divide broadcast domain through VLAN (Virtual LAN). VLAN is a partitioned broadcast domain from a single broadcast domain. Switch doesn't forward packets across different VLANs by itself. If we want to make these virtual LANs communicate with each other, a concept of Inter VLAN Routing is used. Inter V
3 min read
EIGRP Configuration
Prerequisite - EIGRP fundamentals Enhanced Interior Gateway Routing Protocol (EIGRP) is a dynamic routing network-layer Protocol which works on protocol number 88. EIGRP supports classless routing, VLSM, route summarization, load balancing, and many other useful features. It is a Cisco proprietary protocol, so all routers in a network that is runni
3 min read
Open shortest path first (OSPF) router roles and configuration
Prerequisite - Open shortest path first (OSPF) Open shortest path first (OSPF) is a link-state routing protocol which is used to find the best path between the source and the destination router using its own SPF algorithm. Open shortest path first (OSPF) router roles - An area is a group of contiguous networks and routers. Routers belonging to same
3 min read
AAA (Authentication, Authorization and Accounting) configuration (locally)
Prerequisite - AAA (Authentication, Authorization and Accounting) To provide security to access network resources, AAA is used. AAA is a standard based framework used to control who is permitted to use network resources (through authentication), what they are authorized to do (through authorization) and capture the actions performed while accessing
3 min read
Basic configuration of Adaptive Security Appliance (ASA)
Prerequisite - Adaptive security appliance (ASA) Adaptive Security Appliance (ASA) is a Cisco security appliance that combines classic firewall features with VPN, Intrusion Prevention, and antivirus capabilities. It has the capability to provide threat defense before the attacks spread into the networks. As an administrator, we have to ensure prote
5 min read
Article Tags :