How DHCP (Dynamic Host Configuration Protocol) assigns IP address ?
Dynamic Host Configuration Protocol (DHCP) is a client/server protocol that automatically provides an Internet Protocol (IP) host with its IP address and other related configuration information such as the subnet mask and default gateway.
Let's understand the DHCP process in greater detail :-
Consider the above diagram and follow the steps given below :-
RouterD is configured as a DHCP server for the 10.1.4.0/24 network. The hosts on this network can be configured as DHCP clients.
[if !supportLists]1. [endif]Kill the dhclient process on hostD1 (if it is running): sudo killall dhclient [if !supportLineBreakNewLine] [endif]
[if !supportLists]2. [endif]Remove the lease file on hostD1 (if the file exists): sudo rm /var/db/dhclient.leases [if !supportLineBreakNewLine] [endif]
[if !supportLists]3. [endif]Restart the dhclient process on hostD1: sudo /usr/local/sbin/dhclient [if !supportLineBreakNewLine] [endif]
[if !supportLists]4. [endif]Observe the network parameters displayed by dhclient [if !supportLineBreakNewLine] [endif]
[if !supportLists]5. [endif]Observe the DHCP messages in the tcpdump output.
Network configuration on host D1 after DHCP Process
dhclient: New Network Number: 10.1.4.0
dhclient: New Broadcast Address: 10.1.4.255
dhclient: New IP Address (e0): 10.1.4.1
dhclient: New Subnet Mask (e0): 255.255.255.0
dhclient: New Broadcast Address (e0): 10.1.4.255
dhclient: New Routers: 10.1.4.254
Tcpdump output on hostD2:
16:09:51.029554 00:00:0a:01:00:24 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:00:0a:01:00:24, length 300, xid 0xda31572b, Flags [none]
Client-Ethernet-Address 00:00:0a:01:00:24
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Discover
Parameter-Request Option 55, length 7:
Subnet-Mask, BR, Time-Zone, Default-Gateway
Domain-Name, Domain-Name-Server, Hostname
16:09:51.035017 00:00:0a:01:00:12 > 00:00:0a:01:00:24, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
10.1.4.254.67 > 10.1.4.1.68: BOOTP/DHCP, Reply, length 300, xid 0xda31572b, Flags [none]
Your-IP 10.1.4.1
Client-Ethernet-Address 00:00:0a:01:00:24
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Offer
Server-ID Option 54, length 4: 10.1.4.254
Lease-Time Option 51, length 4: 300
Subnet-Mask Option 1, length 4: 255.255.255.0
Default-Gateway Option 3, length 4: 10.1.4.254
Domain-Name Option 15, length 7: "test.ca"
Domain-Name-Server Option 6, length 4: 10.1.0.1
Hostname Option 12, length 14: "hostD1.test.ca"
16:09:51.038897 00:00:0a:01:00:24 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:00:0a:01:00:24, length 300, xid 0xda31572b, Flags [none]
Client-Ethernet-Address 00:00:0a:01:00:24
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Request
Server-ID Option 54, length 4: 10.1.4.254
Requested-IP Option 50, length 4: 10.1.4.1
Parameter-Request Option 55, length 7:
Subnet-Mask, BR, Time-Zone, Default-Gateway
Domain-Name, Domain-Name-Server, Hostname
16:09:51.042918 00:00:0a:01:00:12 > 00:00:0a:01:00:24, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
10.1.4.254.67 > 10.1.4.1.68: BOOTP/DHCP, Reply, length 300, xid 0xda31572b, Flags [none]
Your-IP 10.1.4.1
Client-Ethernet-Address 00:00:0a:01:00:24
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: ACK
Server-ID Option 54, length 4: 10.1.4.254
Lease-Time Option 51, length 4: 300
Subnet-Mask Option 1, length 4: 255.255.255.0
Default-Gateway Option 3, length 4: 10.1.4.254
Domain-Name Option 15, length 7: "test.ca"
Domain-Name-Server Option 6, length 4: 10.1.0.1
Hostname Option 12, length 14: "hostD1.test.ca"
16:09:51.053314 00:00:0a:01:00:24 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Request who-has 10.1.4.1 tell 10.1.4.1, length 28
16:11:50.509090 00:00:0a:01:00:24 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Request who-has 10.1.4.254 tell 10.1.4.1, length 28
16:11:50.509111 00:00:0a:01:00:12 > 00:00:0a:01:00:24, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 10.1.4.254 is-at 00:00:0a:01:00:12, length 28
16:11:50.509113 00:00:0a:01:00:24 > 00:00:0a:01:00:12, ethertype IPv4 (0x0800), length 342: (tos 0x0, ttl 64, id 45834, offset 0, flags [none], proto UDP (17), length 328)
10.1.4.1.68 > 10.1.4.254.67: BOOTP/DHCP, Request from 00:00:0a:01:00:24, length 300, xid 0xda31572b, Flags [none]
Client-IP 10.1.4.1
Client-Ethernet-Address 00:00:0a:01:00:24
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Request
Parameter-Request Option 55, length 7:
Subnet-Mask, BR, Time-Zone, Default-Gateway
Domain-Name, Domain-Name-Server, Hostname
16:11:50.513099 00:00:0a:01:00:12 > 00:00:0a:01:00:24, ethertype IPv4 (0x0800), length 342: (tos 0x0, ttl 64, id 46430, offset 0, flags [none], proto UDP (17), length 328)
10.1.4.254.67 > 10.1.4.1.68: BOOTP/DHCP, Reply, length 300, xid 0xda31572b, Flags [none]
Client-IP 10.1.4.1
Your-IP 10.1.4.1
Client-Ethernet-Address 00:00:0a:01:00:24
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: ACK
Server-ID Option 54, length 4: 10.1.4.254
Lease-Time Option 51, length 4: 300
Subnet-Mask Option 1, length 4: 255.255.255.0
Default-Gateway Option 3, length 4: 10.1.4.254
Domain-Name Option 15, length 7: "test.ca"
Domain-Name-Server Option 6, length 4: 10.1.0.1
Hostname Option 12, length 14: "hostD1.test.ca"
Discussion:
Frame 1 is the BOOTP Ethernet broadcast and IP broadcast which is a DHCP discover.
Frame 2 is the DHCP offer which is Ethernet and IP unicast. This contains the configuration information for the host.
Frame 3 is the DHCP request from the host which is an Ethernet and IP broadcast.
Frame 4 is the DHCP Ack from the server to the host (unicast).
Frame 5 is a gratuitous ARP from the hostD1.
HostD1 is now bound for the lease time (300 seconds).
Frame 6 and 7 are the ARP request and reply between hostD1 and routerD.
Frame 8 is the DHCP request to renew the lease which occur at time 16:09:51. The time interval is 16:09:51 -16:11:50 = 2 minutes and 1 second.
Frame 9 is the DHCP ack from the server. At this point the host is bound again.
Conclusion:
We observed a DHCP client starting up for the first time on a network with a single DHCP server. The client issues a DHCP DISCOVER message, the server responds with a DHCP OFFER message, the client then issues a DHCP REQUEST message and the server responds with a DHCP ACK message. All DHCP messages use the BOOTP message format. After 50% of the lease time the client renews the lease.