dhcp - dwilson2547/wiki_demo GitHub Wiki
- DHCP (Dynamic Host Configuration Protocol) Process: A Detailed Explanation
- DHCP is a network protocol used to automatically assign IP addresses and other network configuration parameters to devices on a network.
- It eliminates the need for manual IP configuration, reducing errors and administrative overhead.
- DHCP operates at the Application Layer (Layer 7) of the OSI model and uses UDP ports 67 (server) and 68 (client).
- DHCP Server: A device (e.g., router, server) that manages and assigns IP addresses.
- DHCP Client: Any device (e.g., laptop, phone) requesting an IP address.
-
DHCP Pool: A range of IP addresses available for assignment (e.g.,
192.168.1.100
to192.168.1.200
). - Lease Time: The duration for which an IP address is assigned to a client.
The DHCP process involves four steps, often referred to as DORA:
- Discover
- Offer
- Request
- Acknowledge
-
Client Action: When a device connects to a network, it sends a DHCP Discover message as a broadcast (destination MAC:
FF:FF:FF:FF:FF:FF
). - Purpose: The client is asking, "Are there any DHCP servers out there?"
-
Message Contents:
- Source MAC: Client’s MAC address.
- Destination MAC: Broadcast (
FF:FF:FF:FF:FF:FF
). - Source IP:
0.0.0.0
(client has no IP yet). - Destination IP:
255.255.255.255
(broadcast). - DHCP Options: Includes the DHCP Discover flag.
- Server Action: Any DHCP server on the network receives the broadcast and responds with a DHCP Offer message, also as a broadcast.
- Purpose: The server offers an available IP address and other configuration parameters.
-
Message Contents:
-
Your Client IP Address: Proposed IP (e.g.,
192.168.1.100
). -
Subnet Mask: (e.g.,
255.255.255.0
). - Lease Time: (e.g., 24 hours).
-
Default Gateway: (e.g.,
192.168.1.1
). -
DNS Servers: (e.g.,
8.8.8.8
). - DHCP Server IP: The server’s IP address.
-
Your Client IP Address: Proposed IP (e.g.,
- Client Action: The client selects one of the offers (if multiple servers respond) and sends a DHCP Request broadcast.
- Purpose: The client confirms which server’s offer it is accepting.
-
Message Contents:
- Requested IP Address: The IP offered by the selected server.
- DHCP Server IP: The IP of the server whose offer is accepted.
- Server Action: The selected DHCP server sends a DHCP ACK message to the client, confirming the assignment.
- Purpose: The server finalizes the IP address assignment and provides all configuration details.
-
Message Contents:
-
IP Address: Confirmed IP (e.g.,
192.168.1.100
). -
Subnet Mask: (e.g.,
255.255.255.0
). - Lease Time: (e.g., 24 hours).
-
Default Gateway: (e.g.,
192.168.1.1
). -
DNS Servers: (e.g.,
8.8.8.8
).
-
IP Address: Confirmed IP (e.g.,
- T1 (Renewal Time): At 50% of the lease time, the client attempts to renew its lease with the original server.
- T2 (Rebinding Time): At 87.5% of the lease time, the client broadcasts a renewal request to any DHCP server if the original server is unavailable.
- Lease Expiry: If the lease is not renewed, the client stops using the IP address and must restart the DORA process.
All DHCP messages use the same format, based on the BOOTP protocol:
Field | Description |
---|---|
Opcode |
1 for request, 2 for reply. |
Hardware Type | Typically 1 for Ethernet. |
Hardware Address Length |
6 for Ethernet MAC addresses. |
Hops | Used by relay agents (usually 0 ). |
Transaction ID | Random number to match requests and replies. |
Seconds | Time elapsed since the client started the DHCP process. |
Flags | Indicates broadcast (e.g., 0x8000 for broadcast). |
Client IP | Filled in by the client if renewing; otherwise 0.0.0.0 . |
Your Client IP | IP address offered by the server. |
Server IP | IP address of the DHCP server. |
Gateway IP | IP address of the relay agent (if used). |
Client MAC | Client’s hardware address. |
Options | Additional configuration (e.g., subnet mask, lease time, DNS servers). |
- Purpose: In large networks, a DHCP relay agent forwards DHCP messages between clients and servers on different subnets.
-
How It Works:
- The relay agent receives the DHCP Discover broadcast.
- It converts the broadcast into a unicast message and forwards it to the DHCP server.
- The server sends the reply back to the relay agent, which then broadcasts it to the client.
- Client (Laptop) connects to the network and broadcasts a DHCP Discover message.
-
DHCP Server (Router) receives the message and responds with a DHCP Offer (e.g.,
192.168.1.100
). -
Client accepts the offer and broadcasts a DHCP Request for
192.168.1.100
. - Server confirms with a DHCP ACK, and the client configures its network interface with the provided IP and settings.
-
No IP Address: If the client fails to receive a DHCP offer, it may use a link-local address (e.g.,
169.254.x.x
). - IP Conflicts: Rare in DHCP but can occur if a static IP is assigned within the DHCP range.
- Slow Response: High network latency or misconfigured relay agents can delay the process.
- Automation: Eliminates manual IP configuration.
- Flexibility: Supports dynamic networks (e.g., Wi-Fi hotspots).
- Scalability: Easily manages large networks with thousands of devices.