DHCP

DHCP (Dynamic Host Configuration Protocol): An application-layer client-server protocol for allowing a device to automatically obtain an IP address.

DHCP also allows a host to learn additional information, e.g. its subnet mask; the address of its first-hop router (i.e. the default gateway); the address of its local DNS server.

A network administrator can configure DHCP so that a host 1) receives the same IP address each time it connects to the network; or 2) is assigned a temporary IP address that will be different each time it connects to the network.

DHCP is often referred to as a plug-and-play protocol.

DHCP is useful in residential Internet access network, wireless LANs and residential ISP access network.

DHCP relies on UDP as its transport layer protocol, it has its own built-in reliability measures.

DHCP Packet Structure

OpCode: indicates whether the packet is a DHCP request or reply;

Hardware type: the type of hardware address, e.g. 10MB Ethernet, IEEE802, ATM;

hardware length: the length of the hardware address;

Hops: Used by relay agents to assist in finding a DHCP server;

Transaction ID: A random number used to pair requests with responses;

Seconds Elapsed: Seconds since the client first requested an address from the DHCP server;

Flags: The type of traffic the DHCP client can accept e.g. unicast, broadcast;

Client IP Address: The client's IP address (derived from Your IP Address field);

Your IP Address: The IP address offered by the DHCP server (ultimately becoms the Client IP Address field value);

Server IP Address: The DHCP server's IP address;

Gateway IP Address: The IP address of the network's default gateway;

Client Hardware Address: The client's MAC address;

Server Host Name: (optional) The server's host name 

Boot File: (optional) A boot file for use by DHCP

Options: Used to expand the structure of the DHCP packet to give it more features.

  Available DHCP options, refer to: www.iana.org/assignments/ bootp-dhcp-parameters 

  Message Type (option 53) is the only option required in all DHCP packets.

4-step process of DHCP Initialization: Discover-Offer-Request-Acknowledgment

-- this DORA process occurs the first time a client gets an IP address or when its lease has expired.

1) DHCP server discovery

The client passes an IP datagram that encapsulate DHCP discover message (a UDP packet to port 67), with broadcast destination IP address (255.255.255.255) and “this host” source IP address (0.0.0.0, because it does not yet have an iP address)to the link layer.

e.g. DHCP discover packet 

requested IP Address: supplies the IP address the client would like to receive, cna be previously used IP address or 0.0.0.0 to indicate no preference.

parameter request list: lists the different configuration items (IP addresses of other important network devices and other non IP items) the client would like to receive from DHCP server. 

2) DHCP server offer(s)

A DHCP server responds with a DHCP offer message (contains the transaction ID of the received discover message, the proposed IP address for the client, other additional information: subnet mask, IP address lease time, router address, domain name ...) that is broadcast to all nodes on the subnet.

e.g. DHCP offer packet

transaction ID: the same as the previous discover packet, indicating this is the response to the original request;

Your IP address: the IP address offered to the client;

3) DHCP request

The client choose from among one or more server offers and respond to one with a DHCP request message, echoing back the configuration parameters.

e.g. DHCP request packet

 - transaction ID is the same as the previous 2 (disover and offer) packets.

4) DHCP ACK

The server responds with a DHCP ACK message, confirming the requested parameters, and records that information in its database.

- The client now has an IP address and can use it to begin communicating on the network.

In-Lease Renewal

A clients is allowed to use the IP adress for only a limited amount of time before it must renew the lease.

in-lease renewal: When a client with an IP address in-lease reboots, it performs truncated version of the DORA process (the discovery and offer packets are removed, leaving only request and acknowledgement) to reclaim its IP address.

DHCPv6 -- IPv6 addressing can’t be supported by traditional DHCP. Unlike DHCP, DHCPv6 isn’t built on the concept of BOOTP.

Standard ports used by DHCPv6: 546, 547.

DHCPv6 Packet Structure

each option is identified with a 2-byte option code and a 2-byte length field.

Available DHCPv6 options, refer to: www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters

DHCPv6 SARR process -- instead of DORA in DHCP

1) Solicit

the client sends an initial packet to special multicast address ff02::1:2, attempting to locate available DHCPv6 servers. 

2) Advertise

an available server responds to the client, indicating it is available;

-- solicit and advertise packets are tied together using the same transaction ID.

3) Request

via multicast, the client sends a formal request for configuration information to the server;

4) Reply

The server sends all available requested configuration information to the client.

-- request and reply packets are tied together using the same transaction ID.

原文地址:https://www.cnblogs.com/RDaneelOlivaw/p/14780450.html