What is DHCP How does it work

DHCP - Dynamic Host Configuration Protocol

DHCP is a protocol for managing IP addresses in a TCP / IP network and distributing them to the requesting hosts. With DHCP, every network participant is able to configure itself automatically.

Why DHCP?

In order to set up a network via TCP / IP, it is necessary to carry out an IP configuration on each host. For a TCP / IP network, the following settings must be made on each host:

  • Allocation of a unique IP address
  • Assigning a subnet mask
  • Assignment of the responsible default or standard gateway
  • Assigning the responsible DNS server

In the first IP networks, IP addresses were still assigned manually and permanently entered in the systems. The documentation required for this, however, was not always error-free and certainly not up-to-date and complete. The call for simple and automatic address management was therefore particularly loud among operators of large networks. The manual administration and configuration required a lot of planning and working time. To make things easier for the operators of the ever-growing networks, DHCP was developed.
With DHCP, every IP host can request the IP address configuration from a DHCP server and configure itself automatically. This means that IP addresses no longer have to be managed and assigned manually.

DHCPv6 / DHCP for IPv6

With IPv6, the IP configuration does not actually require a DHCP service. The Stateless Address Autoconfiguration (SLAAC) is used for this. With SLAAC, an IPv6 host can configure itself fully automatically and obtain the necessary IP configuration. In practice, not all operating systems are capable of this. Some can not receive the DNS server in this way (RDNSS option). In principle, DHCPv6 is the only method that can add this and other information within the IPv6 auto-configuration. In order to enable the same functionalities for IPv6 as with IPv4 with DHCPv4, DHCPv6 was defined.

Allocation of the IP configuration via DHCP

The way DHCP works corresponds to the client-server architecture. The DHCP client asks the DHCP server for an IP configuration. The DHCP server has a pool of IP addresses that it can assign to the DHCP clients. In the case of larger networks, the DHCP server must also know which subnets and standard gateways are available. Usually the DHCP server is a router.
If a host is started with an activated DHCP client, a functionally restricted mode of the TCP / IP stack is operated. This has no valid IP address, no subnet mask and no standard gateway. The only thing the client can do is send IP broadcasts.

DHCP Discover: The DHCP client sends a UDP packet with the destination address 255.255.255.255 and the source address 0.0.0.0. This broadcast serves as an address request to all available DHCP servers. In the best case there is only one DHCP server. This avoids conflicts when assigning addresses.

DHCP offer: The DHCP server replies to the broadcast with a free IP address and other parameters to complete the IP configuration. Each addressed DHCP server sends back a UDP packet with the following data:

  • MAC address of the client
  • possible IP address
  • Runtime of the IP address / configuration (lease time)
  • Subnet mask
  • IP address of the DHCP server / server ID

DHCP request: The DHCP client looks for an IP address from the selection of possibly several DHCP servers. It then sends a positive message to the relevant DHCP server. All other servers also receive the message and assume that the IP address is accepted in favor of another server.

DHCP acknowledgment: The assignment of the IP address must then be confirmed by the DHCP server. But not only the data on the TCP / IP network can be assigned to the client by DHCP. If the DHCP client can evaluate further information, the DHCP server transmits further options:

  • Time server
  • Name server
  • Domain Name Server (alternative)
  • WINS server
  • Domain name
  • Default IP TTL
  • Broadcast Address
  • SMTP server
  • POP3 server

As soon as the DHCP client has received the confirmation, it saves the data locally. Finally the TCP / IP stack is started completely.

DHCP refresh

The lease time is specified in the DHCP-ACK message, which states how long the client may use the assigned IP configuration. After half of the lease time, the standard-compliant client must send another DHCP REQUEST. As a rule, the DHCP server will send a DHCP ACK with identical data and an updated lease time. This means that the use of the IP address is considered extended.

But what if the DHCP server does not respond and thus the current IP configuration is not confirmed / extended. For example, because the DHCP server has failed or has been taken offline. In this case, the client will continue to use the IP configuration without restrictions until the lease time has finally expired. However, before it expires, it will try again to obtain an extension of the IP configuration from this DHCP server.
If this DHCP server can no longer be reached because another DHCP server may be responsible in the meantime, the client will attempt to assign an address from another DHCP server with a new DHCP DISCOVER before the lease time has finally expired to obtain.

DHCP Not Acknowledged

If the DHCP server no longer has any addresses available or if another client has been given this address during the process, the DHCP server sends a DHCPNAK (DHCP-Not Acknowledged).

What happens if the client does not get an IPv4 configuration?

First the reasons:

  • The client is not connected to any network.
  • The client is connected, but there is no DHCP server on the network.
  • The DHCP server is switched off, deactivated or not connected to the network.
  • The DHCP server no longer has any free IP addresses.
  • The DHCP server is incorrectly configured.

In each of these cases, the client will assign itself its own IPv4 address from the link-local address range (169.254.0.0/16). This means that communication is possible at least within the link-local network.
With IPv6, the client automatically generates a link-local IPv6 address via SLAAC.

Configuration of the DHCP client under Windows 2000 / XP

The configuration of the DHCP client under Windows is usually not necessary at all. Most of the time it is already activated. If a DHCP server is installed, the operating system fetches the necessary data itself.
If the TCP / IP configuration was carried out by DHCP, the data can be accessed with the command ipconfig can be viewed on the Windows command line or prompt.

Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C: \> ipconfig Windows IP configuration Ethernet adapter LAN connection: Connection-specific DNS suffix: t-online.de IP address. . . . . . . . . . . . : 192.168.1.11 subnet mask. . . . . . . . . . . : 255.255.255.0 standard gateway. . . . . . . . . : 192.168.1.1

Tasks and exercises with the Raspberry Pi

Other related topics:

Everything you need to know about IPv6.

Collection: IPv6

A PDF file of all articles on Internet Protocol Version 6 from this website. The compilation takes into account the introduction to the basics of IPv6 with detailed descriptions and numerous tables and figures. Learn more about the possibilities and relationships in the IPv6 network.

More information and to download

Everything you need to know about networks.

Network technology primer

The network technology primer is a book about the basics of network technology, transmission technology, TCP / IP, services, applications and network security.

I want that!

Everything you need to know about IPv6.

Collection: IPv6

A PDF file of all articles on Internet Protocol Version 6 from this website. The compilation takes into account the introduction to the basics of IPv6 with detailed descriptions and numerous tables and figures. Learn more about the possibilities and relationships in the IPv6 network.

More information and to download