DHCP stands for Dynamic Host Configuration Protocol and provides a solution that automatically assigns IP addresses to computers on a network. When a client is configured to receive an IP address automatically, It will send out a broadcast to the DHCP server requesting an address. The server will then issue a "lease" and assign it to that client. The time period that a lease will last can be specified on the server. Some of the benefits of DHCP include the following:
Prevents users from making up their own IP addresses and duplicate IP addresses.
Prevents incorrect gateway or subnet masks from being entered.
Decreases amount of time spent configuring computers especially in environments where computers get moved around all the time.
Can be helpful in situations where a certain portion of the staff works in the field and doesn't need an address all of the time. Especially handy when IP addresses are scarce.
How Does This Crazy Thing Work?
It all happens in 4 steps:
The client sends a broadcast that says "Hey, I need an IP address over here". Since it is not configured for TCP/IP yet it uses a source address of 0.0.0.0 and a destination address of 255.255.255.255. The broadcast contains the computer's name and the MAC address so the DHCP server knows where to reply. This is called the IP lease request.
The DHCP server/s send an offer. This broadcast contains the IP address, client's hardware address, subnet mask, duration of lease and the IP address of the responding DHCP server. This process is called a IP lease offer.
The client takes a look at the first offer that it receives and sends a message to all DHCP servers to let them know that it has chosen an offer. This is known as the IP lease selection.
The DHCP server then sends an "ack" (acknowledgement) to the client, all other DHCP servers withdraw their offers and the client now has an IP address. If an unsuccessful ack is received then the client sends out another lease request. Easy eh? For all of you registry nuts, the client stores its IP info in HKEY_LOCAL_MACHINESYSTEMCurrentConrolSetServicesadapterParametersTcpip.
DHCP clients will attempt to renew their leases when 50% of the lease has expired. The client will send a DHCPREQUEST message to the server that assigned the lease. Assuming the DHCP server isn't on fire or anything it will send out a DHCPACK with the new lease. If the server is unavailable, then the client can continue functioning as it has 50% remaining still. The client will continue as normal until the lease reaches 87.5% used at which time it broadcast to all DHCP servers and attempt to get a new lease. If the client receives a DHCPNACK message or the lease expires then the client must start all over again and will get a different IP address. If the lease expires and the client is unable to get a new one then the user will be whining to their IS dept. about it because they will not be able to communicate over the network. DHCP is very seamless and stable, so these types of problems are very rare. IPCONFIG
Below are the ipconfig switches that can be used at a command prompt.
ipconfig /all will display all of your IP settings.
ipconfig /renew forces the DHCP server, if available to renew a lease
ipconfig /release forces the release of a lease.
Setting Up a DHCP Server
We have discussed how DHCP works for the clients, so now we should look at what happens on the rest of the network. First question to ask yourself is how many subnets will the DHCP server serve. If it is more than 1 then you have to make sure that all routers are configured as DHCP relay agents or else only the local subnet will get leases. Next the "scope" needs to be defined. If there are multiple DHCP servers then each one will need to have a unique scope of IP addresses since DHCP servers do not share information about leases with each other. According to Microsoft, each DHCP server should be configured with 75% of the scope reserved for the local subnet and the remaining 25% for remote subnets. This provides redundancy in case a client can't obtain a lease from the local server, then it can get one from a remote server. Also, keep in mind that a DHCP server cannot also be a DHCP client, meaning that the DHCP server must have static entries for its IP settings. While the steps to configure a DHCP server vary depending on the operating system being used, the basic steps are listed below:
The DHCP server service must be installed and activated.
A scope must be defined. Note that each DHCP server must have unique scopes defined or else duplicate IP addresses may be assigned. When creating the scope, you will have options to specify other parameters such as DNS servers, default gateway, subnet mask, WINS server, etc.
You will want to exclude any static IP addresses on the network in the "exclusion" fields. You can also reserve an address for a particular client if you wish them to always receive the same address.
Once these items are configured, you simply need to make sure that the clients on the network are configured to obtain an IP address automatically.
The DHCP server database is backed up every hour by default and can be restored when needed. It may also need to be periodically compacted in order to keep it running efficiently.
DHCP Relay Agent
This service is used when routers separate clients from a DHCP server. A server on the same subnet as the clients can be configured so that it automatically sends all DHCP messages directly to the DHCP server. Included in the message to the server is the address of the originating client so that the DHCP server can respond directly back to the client. This service is basically a middle-man.