Back to Basics — Networking — Auto configuration of IP address-DHCP

Shilpa Thota
8 min readDec 8, 2024

--

Every host on a TCP/IP network must have a unique IP address. Each host must be properly configured so that it knows its IP address. When a new host comes online, it must be assigned an IP address that’s within the correct range of addresses for the subnet but not already in use. Although you can manually assign IP addresses to each computer on your network, that task quickly becomes overwhelming if network has more than a few computers.

Dynamic Host Configuration Protocol (DHCP) automatically configures the IP address for every host on the network, thus assuring that each has valid and unique IP address. DHCP even automatically reconfigures IP addresses as hosts comes and go.

Understanding DHCP

DHCP allows individual computers on a TCP/IP network to obtain their configuration information — in particular their IP Address from a server. the DHCP server keeps track of which IP addresses are already assigned so that when a computer requests and IP address, the DHCP server offers it and IP address that is already in use.

Configuration Information provided by DHCP

Although the primary job of DHCP is to assign IP addresses and subnet masks, DHCP actually provides more configuration information than just the IP address to its clients. The addition configuration information consists of DHCP options.

  • The router address also known as the Default Gateway address
  • The expiration time for the configuration information
  • Domain name
  • Domain name server (DNS) server address
  • Windows Internet Name Service (WINS) server address

DHCP Servers

A DHCP server can be a server computer located on the TCP/IP network. All modern server OS have a built-in DHCP server. To set up DHCP on a network server, all you have to do is enable the server’s DHCP function and configure its settings.

Any file server can act as DHCP server not dedicating to only one server. This is possible with the long leases for your IP addresses. Lease is used by DHCP to indicate that an IP address has been temporarily given out to a particular computer or other device.

Many multifunction routers also have built-in DHCP servers. the advantage is it rarely power down a router. Most networks require only one DHCP server. Setting up two or more servers on the same network requires that you carefully coordinate the IP address ranges for which each server is responsible.

How DHCP Actually works

The DHCP configures TCP/IP hosts every time the we boot up the host computer. Also happens when we release an IP lease and request a fresh lease

  1. When a host computer starts up. The DHCP client software sends a special broadcast packet known as DHCP discover message.

This message uses the subnet’s broadcast address as destination address and 0.0.0.0 as the source address. the client has to specify 0.0.0.0 as the source address because it doesn’t yet have and IP address. IT specifies the broadcast address as the destination address because it doesn’t know the address of any DHCP servers.

2. The DHCP server receives the broadcast DHCP Discover message and responds by sending a DHCP offer message.

The DHCP Offer message includes an IP address that hte client can use. Like the DHCP Discover message, Offer message is sent to broadcast address. This makes sense because the client to which the message is being sent doesn’t yet have an IP Address and won’t have one until it accepts the offer. What if the client never receives a DHCP offer message then the client tries 4 times at 2,4,8,16 seconds and if still doesn't get offer it will try again after 5 minutes

3. The Client receives the DHCP offer message and sends back a message known as DHCP Request message

At this point, the client doesn’t actually own the IP address. It simply indicating that it is ready to accept the IP address that was offered by the server.

4. When the server receives the DHCP Request message, it marks the IP address as assigned to the client and broadcasts a DHCP Ack message

5. When the client receives the DHP Ack Message, it configures its TCP/IP stack by using the address it accepted from the server

Understanding Scopes

A scope is simply a range of IP addresses that a DHCP server is configured to distribute. If DHCP server oversees IP configuration for an entire subnet, the scope corresponds to the subnet. Single DHCP server can serve more than one scope, and a DHCP server can.

Scope looks like this

  • Scope name — Helps to identify the scope and its purpose
  • Scope Definition — Lets you provide additional details about the scope and its purpose
  • Starting IP address — for the scope
  • Ending IP address — for the scope
  • A subnet mask — Specify the subnet mask with dotted-decimal notation or with network prefix notation
  • One or more ranges of excluded addresses — These addresses won’t be assigned to clients
  • One or more reserved addresses — These are always assigned to particular host devices
  • The Lease duration — How long the host will be allowed to use the IP address. the client will attempt to renew lease when half of the lease duration has elapsed
  • The router address — for the subnet, this is also known as Default Gateway Address
  • The domain name and the IP address — of the network's DNS servers and WINS servers

Scopes, Subnets and VLANs

Each VLAN in a network is a separate broadcast domain, a DHCP request from one computer can’t cross over to other VLANs on the network

Two basic ways to solve this problem

  1. Put separate DHCP server on each VLAN. On a big networks this makes sense
  2. There is other way called DHCP relay also known as IP helper

DHVP relay is a routing function that forwards DHCP traffic across VLANs. Most routers can provide for DHCP routing, and many switches can do it as well. This layer 3 function and if switch perform this feature is considered as Layer 3 switch

To Configure a router for DHCP relay, you simply associate a VLAN with DHCP router that is different VLAN. For Example, suppose you have two VLANs-VLAN 20 on subnet 10.0.100.x and LAN 30 on subnet 10.0.200.x — and your DHCP server is at 10.0.100.15 on VLAN 20. The router or switch would be configured to forward all DHCP traffic for VLAN 30 to 10.0.100.15. That way, both VLANs get DHCP from he same server

DHCP scope exclusions can help you to prevent IP address conflicts and can enable you to divide the DHCP workload for a single subnet among two or more DHCP servers

An exclusion is a range of addresses that are not included in a scope, The exclusion range falls within the range of the scope’s starting and ending addresses. In effect, an exclusion range lets you punch a hole in a scope. the IP addresses that fall within the hole won’t be assigned.

  • The computer that runs the DHCP service itself must usually have a static IP address assignement. As a result, the address of he DHCP server should be listed as an exclusion
  • Some hosts, such as a server or printer, may need to have a predictable IP address. In that case, the host will require a static IP address, By excluding its IP address from the scope, you can prevent that address from being assigned to any other host on the network.

Holding back some IP addresses at the bottom and the top of subnet is always a good idea.

Reservations —

In some cases, you may want to assign a particular IP address to a particular host. One way to do this is configure the host with a static IP address so that the host doesn’t use DHCP to obtain its IP configuration.

  • TCP/IP configuration supplies more than just the IP address. If we use static configuration, you must manually specify the subnet mask, the Default Gateway address, the DNS server address, and other configuration information required by the host. If this information changes, you have to change it not only on the DHCP server but also at each host that you configured statically.
  • You must remember to exclude the static IP address rom DHCP server’s scope.

A better way to assign a fixed IP address to a particular host is to create a DHCP reservation. A reservation is simply indicates that whenever a particular host requests an IP address from the DHCP server, the server should provide it the address that you specify in the reservation, the host won’t receive the IP address until the host requests it from the DHCP server, but whenever the host does request IP configuration, it will always receive same address

To create a reservation, you associate the IP address that you want assigned to the host with the host’s Media Access Control address. As a result, you need to get the MAC address from the host before you create the reservation.

Bootstrap Protocol

It is an internet protocol that enables diskless workstations to boot themselves over the internet or local network. Like DHCP, BootP allows a computer to receive an IP address assigned from a server. But BootP enables the computer to download a boot image file which the computer can hen use to boot itself from. A significant difference between BootP and DHCP is that CooP comes into play before the computer actually loads an Operating System. In contrast, DHCP is used after an Operationg system has been loaded during the configuration of netwrok devices.

Most DHCP servers can also support BootP. If your network has diskless workstations, you can use DHCP server’s BootP support to boot those computers, At one time, diskless workstations were all the rage because network administrators thought they would be easier to manage but now BootP is not used much.

How Long to Lease?

One of the most important decisions that you will make when you configure a DHCP server is the length of time to specify for the lease duration. the default values is eight days, which is appropriate in many cases.

  • The more stable your network — The longer the lease duration can safely exist. If you only periodically add new computers to the netwrok or replace existing computers, yo ucan safely increase the lease duration past eight days.
  • The more volatile the netwrok — The shorter the lease duration should be. If it is library where students brings devices for few hours then the short lease duration is appropriate.

Do not configure your network to allow infinite duration leases.

Automatic Private IP addressing

If a windoes computer is configured to use DHCP but the computer cannot obtain an IP address from a DHCP server, the computer automatically assigns itself a private address by using a feature called Automatic Private IP Addressing(APIPA). APIPA assigns a private address from the 169.254.x.x range and uses a special algorithm to ensure taht the address is unique on the network. As soon as the DHCP server becomes available, the computer requests new address, so the APIPA address is used only while the DHCP server is unavailable.

Renewing and Releasing Leases

Normally, a DHCP client attempts to renew is lease when he lease is halfway to the point of being expired. We can also renew a lease sooner by issuing theipconfig /renew command at the command prompt. You may want to do this if you changed the scope’s configuration or if the client’s IP configuration is not working correctly.

You can also release a DHCP lease by issuing the ipconfig /release command at a command prompt. When you release a lease, the client computer no longer has a valid IP address. When you release an IP lease, you cannot communicate with the network by using TCP/IP until you issue an ipconfig /renew command to renew the IP configuration or restart the computer.

Happy Learning!!

--

--

Shilpa Thota
Shilpa Thota

Written by Shilpa Thota

Full Stack Developer#TechEnthusiast#Manager#BigFan of Learning AI#

No responses yet