The
Dynamic Host Configuration Protocol (DHCP) is a network protocol that is used to
configure devices which are connected to a network so that they can communicate on an IP
network. It involves clients and a server operating in a client-server
model. In a typical personal home LAN, a router is the server while clients are
personal computers or printers. The router receives this information through a modem
from an ISP which also operates DHCP servers where the modems are clients. The
clients request configuration settings using the DHCP protocol such as an IP address, a default route and one or more DNS server addresses. Once
the client implements these settings, the host is able to communicate on that internet. The DHCP server
maintains a database of available IP addresses and configuration information.
When the server receives a request from a client, the DHCP server determines
the network to which the DHCP client is connected, and then allocates an IP
address or prefix that is appropriate for the client, and sends configuration
information appropriate for that client. DHCP servers typically grant IP
addresses to clients only for a limited interval. DHCP clients are responsible
for renewing their IP address before that interval has expired, and must stop
using the address once the interval has expired, if they have not been able to
renew it. DHCP is used for IPv4 and IPv6. While both versions serve the same purpose, the
details of the protocol for IPv4 and IPv6 are sufficiently different that they
may be considered separate protocols. Hosts that do not use DHCP for address
configuration may still use it to obtain other configuration information.
Alternatively, IPv6 hosts may use stateless address
autoconfiguration.
IPv4 hosts may use link-local
addressing
to achieve limited local connectivity.
Fig1:IPv
Configurations
The Dynamic Host
Configuration Protocol is used to assign IP addresses to devices on the fly, as
opposed to setting the IP address of the device manually like we did in the
last article. In fact, you probably use DHCP all the time but just aren’t aware
of it, for example when you take your laptop to a coffee shops that have free
Wi-Fi. DHCP is useful in many scenarios with the number of mobile devices we
use on the rise, we find ourselves constantly needing to connect to different
networks. For example, you need to connect your phone to your Wi-Fi at home and
to the Wi-Fi at work. Without DHCP we would have to change the IP address on
our phone every time we got home, or to work.
- Large companies can benefit from DHCP. Can you imagine having to go around and set 1500 IP addresses, only to have the Network and Communication team come to inform you that because of a bad design decision you need to change the IP addresses on all those work stations?
DHCP uses a four
step process, commonly known as DORA, to assign an IP address.
- Discover – When you connect a DHCP enabled device to the network, it broadcasts a message to all nodes on the network (technically this is called a DHCPDiscover packet), asking if anyone on the network is a DHCP server.
- Offer – If a DHCP Server receives the DHCPDiscover packet, it looks in its scope (a fancy name for the list of addresses that it is allowed to give to devices) for an available address which it then in turn sends back to the requester in a DHCPOffer packet.
- Request – When your device receives the DHCPOffer packet it sends a message back to the DHCP server requesting the offered address.
- Acknowledge – The DHCP server then give your client the go ahead to use the IP address using a DHCPAck packet.
Setting up a DHCP server is beyond the scope of this
series, but in order to make sure that your clients are configured to use DHCP,
open the properties of your network card and confirm that it is set to obtain
an IP address automatically.
How DHCP Works:
DHCP provides an automated
way to distribute and update IP addresses and other configuration information
on a network. A DHCP server provides this information to a DHCP client through
the exchange of a series of messages, known as the DHCP conversation or the
DHCP transaction. If the DHCP server and DHCP clients are located on different
subnets, a DHCP relay agent is used to facilitate the conversation.
DHCP Client Functionality
A DHCP client is any
network-enabled device that supports the ability to communicate with a DHCP
server in compliance with RFC 2131, for the purpose of obtaining dynamic
leased IP configuration and related optional information.
DHCP provides
support for client computers running any of the following Microsoft operating
systems:
- Windows NT version 4.0
- Windows 2000
- Windows XP
- Windows Server 2003
- Windows 98
- Windows Millennium Edition
Automatic IP Configuration
DHCP supports
Automatic Private IP Addressing (APIPA), which enables computers running
Windows 2000, Windows XP, and Windows Server 2003 to configure
an IP address and subnet mask if a DHCP server is unavailable at system startup
and the Automatic private IP address Alternate
Configuration setting is selected. This feature is useful for clients on small
private networks, such as a small-business office or a home office.
The DHCP Client
service on a computer running Windows XP and Windows Server 2003 uses
the following process to auto-configure the client:
1.
The DHCP client attempts to locate a DHCP
server and obtain an IP address and configuration.
2.
If a DHCP server cannot be found or does
not respond after one minute, the DHCP client checks the settings on the Alternate
Configuration tab of the properties of the TCP/IP protocol.
If Automatic private IP address is selected, the DHCP client auto-configures its IP address and subnet mask by using a selected address from the Microsoft-reserved Class B network, 169.254.0.0, with the subnet mask 255.255.0.0. The DHCP client tests for an address conflict to ensure that the IP address is not in use on the network.
If Automatic private IP address is selected, the DHCP client auto-configures its IP address and subnet mask by using a selected address from the Microsoft-reserved Class B network, 169.254.0.0, with the subnet mask 255.255.0.0. The DHCP client tests for an address conflict to ensure that the IP address is not in use on the network.
3.
When the DHCP client succeeds in
self-selecting an address, it configures its network interface with the IP
address. The client then continues to check for a DHCP server in the background
every five minutes. If a DHCP server responds, the DHCP client abandons its
self-selected IP address and uses the address offered by the DHCP server (and
any other DHCP option information that the server provides) to update its IP
configuration settings.
Scope:
A scope must be
properly defined and activated before DHCP clients can use the DHCP server for
automatic TCP/IP configuration. A DHCP scope is an administrative collection of
IP addresses and TCP/IP configuration parameters that are available for lease
to DHCP clients of a specific subnet. The network administrator creates a scope
for each subnet.
A scope has the
following properties:
- A scope name, assigned when the scope is created.
- A range of possible IP addresses from which to include or exclude addresses used in DHCP lease offers.
- A unique subnet mask, which determines the network ID for an IP address in the scope.
- Lease duration values.
Each DHCP scope can
have a single continuous range of IP addresses. To use several address ranges
within a single scope you must first define the entire address range for the
scope, and then set exclusion ranges.
DHCP Messages
The following list
includes the eight types of messages that can be sent between DHCP clients and
servers.
DHCPDiscover:
Broadcast by a DHCP
client when it first attempts to connect to the network. The DHCPDiscover
message requests IP address information from a DHCP server.
DHCPOffer:
Broadcast by each
DHCP server that receives the client DHCPDiscover message and has an IP address
configuration to offer to the client. The DHCPOffer message contains an unleased
IP address and additional TCP/IP configuration information, such as the subnet
mask and default gateway. More than one DHCP server can respond with a
DHCPOffer message. The client accepts the best offer, which for a Windows DHCP
client is the first DHCPOffer message that it receives.
DHCPRequest:
Broadcast by a DHCP
client after it selects a DHCPOffer. The DHCPRequest message contains the IP
address from the DHCPOffer that it selected. If the client is renewing or
rebinding to a previous lease, this packet might be unicast directly to the
server.
DHCPAck:
Broadcast by a DHCP
server to a DHCP client acknowledging the DHCPRequest message. At this time,
the server also forwards any options. Upon receipt of the DHCPAck, the client
can use the leased IP address to participate in the TCP/IP network and complete
its system startup. This message is typically broadcast, because the DHCP
client does not officially have an IP address that it can use at this point. If
the DHCPAck is in response to a DHCPInform, then the message is unicast
directly to the host that sent the DHCPInform message.
DHCPNack:
Broadcast by a DHCP
server to a DHCP client denying the client’s DHCPRequest message. This might
occur if the requested address is incorrect because the client moved to a new
subnet or because the DHCP client’s lease has expired and cannot be renewed.
DHCPDecline:
Broadcast by a DHCP
client to a DHCP server, informing the server that the offered IP address is
declined because it appears to be in use by another computer.
DHCPRelease:
Sent by a DHCP
client to a DHCP server, relinquishing an IP address and canceling the
remaining lease. This is unicast to the server that provided the lease.
DHCPInform:
Sent from a DHCP
client to a DHCP server, asking only for additional local configuration
parameters; the client already has a configured IP address. This message type
is also used by DHCP servers running Windows Server 2003 to detect
unauthorized DHCP servers.
Default DHCP Options:
Option
Code
|
Option
Name
|
1
|
Subnet mask
|
3
|
Router
|
6
|
DNS servers
|
15
|
DNS domain name
|
44
|
WINS/NBNS servers
|
46
|
WINS/NetBT node type
|
47
|
NetBIOS scope ID
|
51
|
Lease time
|
58
|
Renewal (T1) time value
|
59
|
Rebinding (T2) time value
|
31
|
Perform router discovery
|
33
|
Static route
|
43
|
Vendor-specific information
|
249
|
Classless static routes
|
APIPA (Automatic Private IP Addressing):
A Windows 7
computer that is configured to use DHCP can automatically assign itself an IP
address if a DHCP server is not available. For example, this could occur on a
network without a DHCP server or on a network if a DHCP server is temporarily
down for maintenance. The Internet
Assigned Numbers Authority has reserved 169.254.0.0-169.254.255.255 for
Automatic Private IP Addressing. As a result, APIPA provides an address that is
guaranteed not to conflict with any devices on your network. After the network
adapter has been assigned an IP address, the computer can communicate with any
other computer that is connected to the same networks and that is also
configured for APIPA. When troubleshooting, if a DHCP enabled computer has an
APIPA address it is often a sign that it can’t connect to the DHCP server.
To elaborate
yourselves more about DHCP, you can watch the videos on following links.