3

I understand that IP address is a unique address to identify a machine in a network. But for the first time when i Plug in say ethernet cable of a network to my PC's Ethernet Port, how the IP address is assigned? Let's rule out static IP address where you can configure manually.

How a DHCP assigns a IP address when i Plugin network cable for first time.

15

The basic process is quite simple. I'll only cover that and omit scenarios where several DHCP servers exist, error conditions crop up or discovery has to cross network boundaries.

  1. A new client on a network sends a DHCPDISCOVER via udp from address 0.0.0.0 to 255.255.255.255:67 (broadcast, port 67).
  2. If there is at least one DHCP servers listining in the network segment it responds with a DHCPOFFER to broadcast on port 68. DHCPOFFER includes all required settings for the client.
  3. The client now sends DHCPREQUEST to the DHCP server, still using the anonymous 0.0.0.0 address.
  4. The contacted DHCP server replies with a DHCPACK, which signals to the client that it may use the provided details.

For more information on the DHCP packet content and what to do in error cases read the Wikipedia article: https://en.wikipedia.org/wiki/DHCP

  • Thanks bjanssen. I got basic idea now how client get ip address through dhcp. Wiki should answer all my questions. – Nafri999 Aug 4 '14 at 14:39
  • In step 2, when no DHCP server is in the same network, an "ip helper-address" on Cisco gear is required to take the broadcast and unicast it to a DHCP server on another network. There's a bit more under the hood in this case such as helping the non-local DHCP server identify what network the request originated from so the server knows which DHCP pool to use. – generalnetworkerror Aug 4 '14 at 18:23
  • 1
    @generalnetworkerror: That's just one vendor specific way of naming DHCP-relaying. Relaying is required to cross network boundaries and always works by setting up a local agent who does the talking to a DHCP server in another network. Obviously the agent must have a presence in both networks, so routers or switches with at least some layer 3 capabilities are the logical choice for such an agent. The agent relays the communications but puts his own IP as gateway address (GIADDR). The DHCP server uses this address to figure out which subnet to serve. It's actually quite simple. – bjanssen Aug 5 '14 at 5:16
  • @bjanssen, I didn't doubt you understood DHCP relaying. I just added the comment for completeness to your answer for others. – generalnetworkerror Aug 5 '14 at 7:25
  • @generalnetworkerror, no offence taken. I just tried to generalize your statement to other vendors. I think there is much too much talk of Cisco around here ;) – bjanssen Aug 6 '14 at 5:46
4

A DHCP server has a pool of addresses. When your client request an IP address the server will handout one of its free pool. If there are no addresses left, your client will not get an address.

The address assignment has a certain lifetime. If the request is not renewed within this time the address will go back too the pool and can be handed out to the next client requesting an IP.

0

After browsing few sites, I come across a youtube video which explains DHCP very well. Here it is : https://www.youtube.com/watch?v=RUZohsAxPxQ

Hope it may help few more people like me..

-1

1) Client makes a UDP Broadcast to the server about the DHCP discovery sPort=67 dPort=68. 2) DHCP offers to the client. 3) In response to the offer Client requests the server. 4)Server responds all the Ip Add/ subnetmask/default gateway/dns/wins info along with the acknowledgement packet.

Hope this answers you're query... Thanks

  • 1
    That's not entirely correct. The details (IP, gateways, subnet etc.) are provided during step 2. Before step 3 the client checks the details for availability and sanity. It starts using the details on step 4. – bjanssen Aug 4 '14 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.