DHCP is an abbreviation for Dynamic Host Configuration Protocol. It is an application layer protocol used by hosts for obtaining network setup information. The DHCP is controlled by DHCP server that dynamically distributes network configuration parameters such as IP addresses, subnet mask and gateway address.
What is Dynamic host configuration protocol?
- Dynamic – 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
Summing up, a DHCP server dynamically configures a host in a network.
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. Say a Network administrator might assign an IP address which was already assigned. Thus, causing difficulty for both administrator as well as neighbors on network.
So, here comes the use of DHCP server. Before discussing about how DHCP server works, lets go through the DHCP entities.
Configuring a host using DHCP
To configure a host, we require the following things:
- Leased IP address – IP address to a host which lasts for a particular duration which goes for a few hours,few days or few weeks.
- Subnet Mask – The host can know on which network it 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 the gateway is to connect to the internet.
- DHCP server: It automatically provides network information(IPaddress, subnet mask, gateway address) on lease. Once the duration is expired, that network information can be assigned to other machine. It also maintains the data storage which stores the available IP addresses.
- DHCP client: Any node which request an IP address allocation to a network is considered as DHCP client.
- DHCP Relay Agent: In case, we have only one DHCP server for multiple LAN’s then this Agent which presents in every network forwards the DHCP request to DHCP server. So, using DHCP Relay Agent we can configure multiple LAN’s with single server.
How DHCP server assigns IP address to a host?
- DHCPDISCOVER: When a new node is connected to the network, it broadcasts the DHCPDISCOVER message which contains the source address as 0.0.0.0 to every node on the network including server. DHCP server on receiving the message, returns the DHCPOFFER message to the requested host which contains the server address and new IP address to the node.
- DHCPOFFER: If there are multiple servers on the network, host receives multiple DHCPOFFER messages. It is up to the host to select a particular message.
- DHCPREQUEST: The requested host on receiving the offer message, it again broadcasts the DHCPREQUEST message on the network with the address of the server whose offer message is accepted by the host. The server which pertains to that server address sent by the host checks whether the address to be assigned to the node is available in the data storage.
- DHCPACK : If the address is assigned , it marks the IP address in the storage as unavailable to ensure consistency. Now, the server sends DHCPACK packet to the requested host which contains network information(IP address, subnet mask, gateway address). In case, if the address is assigned to other machine meanwhile, then the server sends the packet DHCPNAK to the requested host indicating that the IP address is assigned to some other machine.
- DHCPRELEASE : And finally, If the host wants to move to other network or if it has finished its work, it sends the DHCPRELEASE packet to the server indicating that it wants to disconnect. Then the server marks the IP address as available in the storage so that it can be assigned to other machine.
For reference to DHCP protocol, click here
This article is contributed by Brahmani Sai. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Computer Network | Dynamic Host Configuration Protocol (DHCP)
- Program to determine class, Network and Host ID of an IPv4 address
- Program to determine Class, Broadcast address and Network address of an IPv4 address
- Computer Network | DHCP Relay Agent
- How to host a website on IBM Cloud
- Computer Network | What is Local Host?
- Using GitHub to host a free static website
- TCP and UDP server using select
- TCP Server-Client implementation in C
- JSF | Java Server Faces
- UDP Server-Client implementation in C
- DNS (Domain Name Server) | NetWorking
- Extracting MAC address using Python
- Finding IP address of a URL in Java
- How slow HTTP can knock down a server?