CNP Chap-18 DHCP
CNP Chap-18 DHCP
Each computer that uses the TCP/IP protocol suite needs to know its IP
address.
Before DHCP became the formal protocol for host configuration, some other
protocols were used for this propose.
RARP
Reverse Address Resolution Protocol (RARP) was designed to provide the IP
address for a booted computer.
• When a client requests its IP address, the BOOTP server consults a table that
matches the physical address of the client with its IP address.
• Binding between physical address and the IP address of the client already
exists.
The DHCP client and server can either be on the same network
or on different networks.
1. DHCP server issues a passive open command on UDP port number 67 and
waits for a client.
2. A booted client issues an active open command on port number 68. The
message is encapsulated in a UDP user datagram, using the destination port
number 67 and the source port number 68. The client uses all 0s as the source
address and all 1s as the destination address.
3. The server responds with either a broadcast or a unicast message using UDP
source port number 67 and destination port number 68. The response can be
unicast because the server knows the IP address of the client.
The DHCP request is broadcast because the client does not know the
IP address of the server.
One of the hosts (or a router that can be configured to operate at the application
layer) can be used as a relay. The host in this case is called a relay agent.
Relay agent knows unicast address of a DHCP server and listens for broadcast
messages on port 67.
The packet, carrying a unicast destination address, is routed by any router and
reaches the DHCP server.
The DHCP server knows the message comes from a relay agent because one of the
fields in the request message defines the IP address of the relay agent.
The relay agent, after receiving the reply, sends it to the DHCP client.
Figure 18.3 shows the interaction between a client and a DHCP server.
• The server uses the well-known port 67, which is normal.
• The client uses the well-known port 68, which is unusual.
The reason for choosing the well-known port 68 instead of an ephemeral port is to
prevent a problem when the reply, from the server to the client, is broadcast.
• Suppose host A on a network is using a DHCP client on ephemeral port 2017 (randomly
chosen). Host B, on the same network, is using a DAYTIME client on ephemeral port 2017
(accidentally same).
• DHCP server sends a broadcast reply message with the destination port number 2017 and
broadcast IP address FFFFFFFF16.
• Every host needs to open a packet carrying this destination IP address. Host A finds a
message from an application program on ephemeral port 2017. A correct message is
delivered to the DHCP client.
• An incorrect message is delivered to the DAYTIME client.
• Confusion is due to the demultiplexing of packets based on the socket address, which is a
combination of IP address and port number. In this case, both are the same.
TCP/IP Protocol Suite 16
UDP Ports
Use of a well-known port (less than 1024) prevents the use of same two
destination port numbers.
• The socket address is the same and both clients will receive the message.
• DHCP uses another number, called the transaction ID, which is randomly
chosen for each connection involving DHCP.
• It is highly improbable that two hosts will choose the same ID at the same
time.
Server does not send all of the information that a client may need for booting.
In reply message, server defines the pathname of a file in which the client can
find complete booting information.
Client can then use a TFTP message, which is encapsulated in a UDP user
datagram, to obtain the rest of the needed information.
DHCP uses UDP, which does not provide error control. Therefore, DHCP must
provide error control.
1. DHCP requires that UDP uses the checksum. Use of checksum in UDP is
optional.
2. DHCP client uses timers and a retransmission policy if it does not receive the
DHCP reply to a request. To prevent a traffic jam when several hosts need to
retransmit a request (after a power failure), DHCP forces the client to use a
random number to set its timers.
Packet Format
Operation code. 8-bit field defines type of DHCP packet: request (1) or reply (2).
Hardware type. 8-bit field defining the type of physical network. For Ethernet the value
is 1.
Hardware length. 8-bit field defining length of physical address. For Ethernet the value
is 6.
Hop count. 8-bit field defining the maximum number of hops the packet can travel.
Transaction ID. 4-byte field carrying an integer. Transaction identification is set by the
client and is used to match a reply with the request. Server returns the same value in its
reply.
TCP/IP
NumberProtocol Suite
of seconds. 16-bit field that indicates the number of seconds elapsed since the 21
Figure 18.5 Flag format
Flag.
16-bit field in which only leftmost bit is used and rest of the bits should be set to
0s.
A leftmost bit specifies a forced broadcast reply (instead of unicast) 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.
Since the client does not know its IP address, it may discard the packet.
If the IP datagram is broadcast, every host will receive and process the broadcast
message.
Your IP address. 4-byte field that contains the client IP address. It is filled by the
server (in the reply message) at the request of the client.
Server IP address. 4-byte field containing the server IP address. It is filled by the
server in a reply message.
Server name. 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 field with data, the server must fill it with all 0s.
Options. An option is composed of three fields: a 1-byte tag field, a 1-byte length
field, and a variable-length value field. The length field defines the length of the
value field, not the whole option.
When a DHCP client sends a request to a DHCP server, server first checks
its static database.
If the entry does not exist in static database, server selects an IP address
from available pool, assigns address to the client, and adds entry to the
dynamic database.
DHCP server issues a lease for a specific period of time. When the lease
expires, the client must either stop using the IP address or renew the
lease.
Server has the choice to agree or disagree with the renewal. If the server
disagrees, the client stops using the address.
Transition States
To provide dynamic address allocation, DHCP client acts as a state machine that
performs transitions from one state to another depending on messages it receives
or sends.
The type of message in this case is defined by the option with tag 53 that is
included in DHCP packet.
Figure 18.7 shows the type option and the interpretation of its value to define the
type of the DHCP packet.
Figure 18.8 shows the transition diagram with main states.
INIT State When the DHCP client first starts, it is in the INIT state. The client broadcasts a
DHCPDISCOVER message, using port 67.
SELECTING State After sending the DHCPDISCOVER message, client goes to the selecting
state. Those servers that can provide this type of service respond with a DHCPOFFER message.
In these messages, the servers offer an IP address. They can also offer lease duration. The
default is 1 hour. The client chooses one of the offers and sends a DHCPREQUEST message to
the selected server. It then goes to the requesting state. However, if the client receives no
DHCPOFFER message, it tries four more times, each with a span of 2 seconds. If there is no reply
to any of these DHCPDISCOVERs, client sleeps for 5 minutes before trying again.
REQUESTING State The client remains in requesting state until it receives a DHCPACK
message from server that creates the binding between client physical address and its IP
address. After receipt of the DHCPACK, client goes to the bound state.
BOUND State In this state, client can use the IP address until lease expires. When 50 percent of
the lease period is reached, client sends another DHCPREQUEST to ask for renewal. It then goes
to the renewing state. When in the bound state, the client can also cancel the lease and go to
the state.client remains in renewing state until one of two events happens. It can
initializingState
RENEWING
receive a DHCPACK, which renews lease agreement. In this case, client resets its timer and goes
back to bound state. Or, if a DHCPACK is not received, and 87.5 percent of lease time expires,
client goes to the rebinding state.
REBINDING State client remains in rebinding state until one of three events happens. If the
client receives a DHCPNACK or the lease expires, it goes back to the initializing state and tries to
get another
TCP/IP IP address.
Protocol Suite If the client receives a DHCPACK, it goes to the bound state and resets32
the timer.
Other Issues
Early Release A DHCP client that has been assigned an address for a period of
time may release the address before expiration time. The client may send a
DHCPRELEASE message to tell the server that address is no longer needed. This
helps server to assign the address to another client waiting for it.
Timers above discussion requires that client uses 3 times: renewal timer, rebinding
timer, and expiration timer. If the server does not specify time-out values for these
timers when the address is allocated, client needs to use the default value. default
value for each timer is shown below:
Exchanging Messages
Exchange of messages related to the transition diagram.