Sunday 20 October 2019

What is DHCP and How It Works

What is DHCP and How It Works

In this post you learn about What is DHCP and How It Works. This article explain Introduction to DHCP, IP address, DHCP operations and DHCP message format.

What is DHCP ?

DHCP assigns IPv4 addresses and other network configuration information dynamically. Since desktop clients often make up a large part of network nodes, DHCP is an extremely useful tool for network administrators and saves a lot of time.
A dedicated DHCP server is scalable and relatively easy to manage. However, in a small branch or SOHO location, a Cisco router can be configured to provide DHCP services without the need for a dedicated server. The Cisco IOS software supports a DHCP server with optional full functions.

The DHCP server dynamically assigns, or leases, an IPv4 address from a set of addresses for a limited period chosen by the server or until the client no longer needs the address.
Clients lease the server information for an administratively defined period. Administrators configure DHCP servers to establish leases, so that they expire at different intervals. The lease typically lasts 24 hours to a week or more . When the lease expires, the client must request another address, although it is usually reassigned.

Introduction to IP Addresses

Every device that connects to a network needs a unique IP address. Network administrators assign static IP addresses to routers, servers, printers and other network devices whose locations (physical and logical) probably do not change. In addition, static addresses enable administrators to administer these devices remotely. Network administrators find it easier to access a device when they can easily determine its IP address.
However, computers and users in an organization often change location, physically and logically. For network administrators, assigning new IP addresses each time an employee changes location can be difficult and time consuming. In addition, for mobile employees working from remote locations, it can be difficult to manually set the correct network parameters. Even for desktop clients, the manual assignment of IP addresses and other addressing information poses an administrative burden, especially as the network grows.
The introduction of a Dynamic Host Configuration Protocol (DHCP) server in the local network simplifies the assignment of IP addresses to both desktop and mobile devices. The use of a centralized DHCP server allows organizations to manage all IP address assignments from a single server. This practice makes IP address management more efficient and ensures consistency throughout the organization, including branches.

DHCP OPERATION

As shown in Image 2, DHCP works in a client / server mode. When a client communicates with a DHCP server, the server assigns or leases an IPv4 address to that client. The client connects to the network with that leased IP address until the lease expires. The client must contact the DHCP server periodically to extend the lease. This leasing mechanism ensures that customers who move or disconnect do not keep the addresses they no longer need. When a lease expires, the DHCP server returns the address to the set, where it can be reassigned as necessary.

ORIGIN OF THE LEASE

When the client starts (or wants to join a network), a four-step process begins to obtain a lease. As shown in Image 3, a client starts the process with a DHCPDISCOVER broadcast message with its own MAC address to detect available DHCP servers.

DHCP DETECTION

The DHCPDISCOVER message finds the DHCP servers in the network. Since the client does not have valid IPv4 information during startup, it uses Layer 2 and Layer 3 broadcast addresses to communicate with the server.

DHCP OFFER 

When the DHCP server receives a DHCPDISCOVER message, it reserves an available IPv4 address to lease to the client. The server also creates an ARP entry that consists of the MAC address of the client making the request and the leased IPv4 address of the client. The DHCP server sends the DHCPOFFER message assigned to the client making the request. The DHCPOFFER message is sent as a unicast, and the server's layer 2 MAC address is used as the source address and the client's layer 2 MAC address as the destination.

DHCP REQUEST (DHCPREQUEST)

When the client receives the DHCPOFFER message from the server, it sends a DHCPREQUEST message, as shown in Image 5. This message is used both for the origin and for the renewal of the lease. When used for the origin of the lease, the DHCPREQUEST message serves as a binding acceptance notification to the selected server for the parameters offered and as an implicit rejection to any other server that could have provided a binding offer to the client.
Many business networks use several DHCPv4 servers. The DHCPREQUEST message is sent in broadcast form to inform this DHCPv4 server and any other DHCPv4 server about the accepted offer.

DHCP ACKNOWLEDGMENT (DHCPACK)

Upon receiving the DHCPREQUEST message, the server verifies the lease information with an ICMP ping to that address to ensure that it is not in use, creates a new ARP entry for the client's lease and responds with a unicast DHCPACK message, as shown in Image 6. The DHCPACK message is a duplicate of the DHCPOFFER message, except for a change in the message type field. When the client receives the DHCPACK message, it records the configuration information and performs an ARP search for the assigned address.

LEASE RENEWAL

In following figure, before the lease expires, the client sends a DHCPREQUEST message directly to the DHCPv4 server that offered the IPv4 address in the first instance. If a DHCPACK message is not received within a specified amount of time, the client transmits another DHCPREQUEST message so that one of the other DHCPv4 servers can extend the lease.

DHCP ACKNOWLEDGMENT (DHCPACK)

Upon receiving the DHCPREQUEST message, the server verifies the lease information by returning a DHCPACK.

DHCP MESSAGE FORMAT

The DHCPv4 message format is used for all DHCPv4 transactions. DHCPv4 messages are encapsulated within the UDP transport protocol. If DHCPv4 messages are sent from the client, they use UDP source port 68 and destination port 67. And if DHCPv4 messages are sent from server to client they use UDP source port 67 and destination port 68.

 DHCPV4 MESSAGE FORMAT FIELDS


  • Operation code (OP):  Specifies the type of general message. The value 1 indicates a request message and the value 2 is a response message.
  • Hardware Type:  Identifies the type of hardware used in the network. For example, 1 is Ethernet, 15 is Frame Relay and 20 is a serial line. These are the same codes that are used in ARP messages.
  • Hardware address length:  Specifies the length of the address.
  • Hops:  controls message forwarding. A customer sets it to 0 before transmitting a request.
  • Transaction identifier:  used by the client to match the request with responses received from DHCPv4 servers.
  • Seconds:  Identify the number of seconds elapsed since a customer began trying to acquire or renew a lease. It is used by DHCPv4 servers to prioritize responses when there are several pending client requests.
  • Indicators:  used by a client who does not know his IPv4 address when sending a request. Only one of the 16 bits is used, which is the diffusion indicator. The value 1 in this field tells the DHCPv4 server or the relay agent that receives the request that the response should be sent as a broadcast.
  • Client IP address:  used by a client during the renewal of the lease when the client's address is valid and usable, not during the process of acquiring an address. The client places its own IPv4 address in this field only if it has a valid IPv4 address while in the linked state. Otherwise, set the field to 0.
  • Your IP address:  used by the server to assign an IPv4 address to the client.
  • Server IP address:  used by the server to identify the address of the server that the client should use for the next step in the bootstrap process, which may or may not be the server that sends this response. The sending server always includes its own IPv4 address in a special field called the DHCPv4 Server Identifier option.
  • Gateway IP address:  routes DHCPv4 messages when DHCPv4 relay agents intervene. The gateway address facilitates communications of DHCPv4 requests and responses between the client and a server that are located on different subnets or networks.
  • Client hardware address: Specifies the client's physical layer.
  • Server Name:  used by the server that sends a DHCPOFFER or DHCPACK message. The server can optionally place its name in this field. It can be a simple text nickname or a DNS domain name, such as dhcpserver.netacad.net.
  • Boot File Name:  An optional client uses it to request a certain type of boot file in a DHCPDISCOVER message. It is used by a server in a DHCPOFFER to fully specify a file directory and a boot file name.
  • DHCP Options:  Contains DHCP options, including several parameters required for basic DHCP operation. This field is of variable length. Both the client and the server can use it.

DISCOVER AND OFFER MESSAGES FROM DHCPV4

If a client is configured to receive its IPv4 configuration dynamically and wishes to join the network, it requests addressing values ​​from the DHCPv4 server. The client transmits a DHCPDISCOVER message on its local network when it starts or detects an active network connection. Since the client has no way of obtaining information about the subnet to which it belongs, the DHCPDISCOVER message is an IPv4 broadcast (destination IPv4 address 255.255.255.255). The client does not yet have an IPv4 address configured, so the source IPv4 address 0.0.0.0 is used.
When the DHCPv4 server receives the DHCPDISCOVER message, it responds with a DHCPOFFER message. This message includes initial configuration information for the client, such as the IPv4 address that the server offers, the subnet mask, the lease duration, and the IPv4 address of the DHCPv4 server that makes the offer.
It is possible to configure the DHCPOFFER message to include other information, such as the lease renewal time and the DNS address.
The DHCP server responds to the DHCPDISCOVER message by assigning values ​​to the CIADDR and the subnet mask. The frame is created by the client hardware address (CHADDR) and sent to the client making the request.

No comments:

Post a Comment