DHCP is successor of BOOTP. DHCP and BOOT share same message format. RARP can also be used to distribute IP address to machine but other parameters cannot be distributed and RARP works in same physical network. In case of RARP network administrator have to manually assign IP address to each mac address. BOOTP doesnot have dynamic address allocation capability so DHCP came into picture.
DHCP and BOOTP uses UDP one reason is that TCP doesn’t support broadcast. Now as most to traffic is broadcast so the packets exchanged will be delivered to all hosts in the network, If client uses any random source port it is possible that that port may be used by any other host so the reply from the server might confuse that other host so just to avoid confusion client listen on standard udp port 67.
UDP is connectionless protocol so if the traffic is dropped in between retransmission is used.
DHCP message format:
| op (1) | htype (1) | hlen (1) | hops (1) |
| xid (4) |
| secs (2) | flags (2) |
| ciaddr (4) |
| yiaddr (4) |
| siaddr (4) |
| giaddr (4) |
| chaddr (16) |
| sname (64) |
| file (128) |
| options (variable) |
hops: Client will set the value of this field to zero and this field can be used to count the number of relay agent forwarded this message.
xid (Transaction ID): -Client might have send multiple request and it might have receieved multiple response so to match request with response xid(Transaction ID) is used.
ciaddr(client ip address): This field contain current IP address of the client. For example client is trying to renew ip address lease then in that case client will fill ciaddr field with the current ip address.
siaddr(Next server ip address): This field provide IP address of next server to use for Bootp process..
yiaddr(Your ip address): This field contain the ip address which DHCP server is offering to the DHCP client.
Giaddr(Relay ip address): giaddr field is filled by DHCP relay agent. If there are multiple relay agent this field is field by first relay agent and if there are transit relay agent then they will not modify this field.
chaddr: This field contain the hardware address of the client.
DHCP messages: There are 8 types of messages in DHCP.
DHCPNAck: This message can be sent in various situation.For example:
- When DHCP client is trying to renew the lease then this message can be sent. DHCPNAck will be sent sent by server if the client is trying to renew a lease after moving to some different network or Client is trying to renew its leease after lease has expired. Upon receiving DHCPNack client move to init state.
Whenever a DHCP client gets an IP address from DHCP server before using it client checks if that IP address have been used already or not. If it is being used then a DHCPDecline message is send to server. DHCPDecline message is broadcast. While renewing the DHCP lease gratitous ARP is not used to check if the IP address is already being used or not.
If a DHCP client want to release IP address that it has got from the dhcp server client will send a unicast DHCPrelease message to the server.
DHCPinform message can be used by a client to get few parameters from the dhcp server. Client might have received ip address information from some other mean but client needs other parameter for this client can use DHCPinform message to get the required parameters. DHCPinform message can be sent either to broadcast address if the DHCP server is not known or to unicast address if DHCP server is known.
There are following states in DHCP:
- Init:This is initial state. DHCP client will be in this state initially. DHCP client can be in this state if the DHCP lease expires.
- Selecting:In this state the client is waiting for the reply of the DHCP discover message from DHCP servers, means client is waiting for DHCP offer message from server/servers.
- Requesting:Client selects the offer it have received from the DHCP server and sends DHCP request message in the state.
- Bind:Client have received DHCPAck from the server and it means that now client have valid IP address and other DHCP parameters to use.
- Renewing: Client have the IP address and now it is try to renew the lease. In this state client send DHCPRequest message to the DHCP server who have offered the IP address and other information. Renewing of IP starts after half of the lease have expired.
- Rebinding: In this state client is not able to renew its lease with the DHCP server which have offered the DHCP information. Now DHCP client will try to send the DHCPRequest message to broadcast IP address and try to renew the lease to any of the avail DHCP server. Client trys to renew the lease with other DHCP server when 87.5% of the lease have expired. If no server replies or if a DHCPNack have been received then the DHCP client will immediately stops using the IP address and enters into INIT state.
- Init-Reboot: Client will be in this state if client reboots or powered up and have a valid lease from previous DHCP DORA process. Client will try to send and DHCPRequest message to verify if it can still use the same IP address. From this state client moved to Rebooting state.
- Rebooting:Client is waiting for reply of DHCPDiscover message sent in Init-Reboot state.
DHCP allocation method:
- Manual allocation: Network admin will allocate the IP address to devices manually DHCP will be used to convey that info to the end host.
- Automatic allocation: DHCP will assign IP address to end host and the lease will be permanent.
- Dynamic allocation: DHCP will allocate the IP address to end host from a pool for some period of time once the lease expires host has to renew the lease.
Timer in DHCP: DHCP server maintain the lease which it has allocated to client. Client keep track of the lease so that it can request for extension when needed. Client initate the lease extension.
- Renewal timer (T1): The value of this timer is 50% of the lease. Whenever 50% of the lease time is passed client initiate the process of renewal with the server who have assigned the IP address. Client sends DHCPRequest message direclty to the server who have issued address.
- Rebinding time(T2): The value of this time is 87.5% of the lease. After 87.5% of lease time client try to renew its lease to another DHCP server in the network as the renewal with the server who have assigned have failed. In this client will send a broadast DHCPRequest message.
DHCP relay agent:
When the DHCP server is not in local subnet then in that case we can configured DHCP relay agent to sent the broadcast request as unicast to DHCP server located in another segment. When DHCP relay agent receive a DHCP discover message it does following:
- Increment hop file of dhcp header.
- The first DHCP relay agent will fill giaddr field with the IP address of the interface on which the DHCPOffer is received.
- Change the source IP address of the DHCPOffer to the IP address of the interface on which the DHCPOffer is received.
- Change the destination IP address of DHCPOffer to the IP address of configured DHCP server.
When DHCP server receive the DHCPOffer from DHCP relay agent it does following:
It takes the Relay IP Address and do a AND operation with subnet masks of configured scopes so that it can find a scope whose network ID matches the network ID of the Relay IP Address. When a match is found, the DHCP server allocates an IP address from that scope. DHCP sever send unicast reply to DHCP relay agent.
Multiple DHCP offer:
If client gets multiple DHCP offer from various server then client might take the first offer that it have receieved or else it will wait for other DHCP server to reply and take the offer that suites best.
Offered address not avail on server:
If the ip address offered in DHCP offer is not avail then DHCP server will reply back with DHCPNack and then client might try to send DHCP request to another server if avail or else client will start the DHCP process from scratch.
Offered IP is in use:
Once client gets DHCPAck message client will verify if the offered address is being used by someone else or not this is done with the help of sending gratitous ARP if a reply comes then it mean that someone is using the IP address and DHCP client wil send DHCPDecline message to server and start the process from scratch.
What if client doesn’t get any reponse from any server while renewing/rebinding the IP address lease?
Client keep on trying to renew the IP address lease to the server who have give the address by sending unicast DHCPrequest message. If the T1 timer expires then client will try to send broadcast DHCPdiscover message. If still client doesn’t receive any reply then when lease expires client stops using IP address and fall back to init state.
|Option 1||Subnet mask||This option specify the subnet mask to be used by client.|
|Option 3||Router||This option tells to client what is your default gateway.|
|Option 6||DNS servers||This option tells to client what dns server/servers to be used by client.|
|Option 51||Lease time||This is option tells what is the lease time i.e how long a dhcp client can use the IP address.|
|Option 53||This is option tells what type of DHCP message is this.|
|Option 58||Renewal (T1) time value||The time in seconds from address assignment until the client enters the Renewing state.|
|Option 53||Rebinding (T2) time value||The time, in seconds, from address assignment until the client enters the Rebinding state.|
|Option 150, 66||When a CISCO IP Phone boots up, if may not have its own IP address and it may not know the ip address of TFTP server. To get the IP address of the TFTP server Option 150,66 can be used. Option 150 can provide of list of IP address and option 66 can provide only one IP address of TFTP server|