Chapter 5

DHCP

IN THIS CHAPTER

check Discovering the basics of DHCP

check Exploring scopes

check Configuring a DHCP server

check Setting up a DHCP client

Every host on a Transmission Control Protocol/Internet Protocol (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 the network has more than a few computers.

That’s where DHCP — Dynamic Host Configuration Protocol — comes into play. DHCP automatically configures the IP address for every host on a network, thus assuring that each host has a valid, unique IP address. DHCP even automatically reconfigures IP addresses as hosts come and go. As you can imagine, DHCP can save a network administrator many hours of tedious configuration work.

In this chapter, you discover the ins and outs of DHCP: what it is, how it works, and how to set it up.

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 an IP address, the DHCP server offers it an IP address that’s not already in use.

Configuration information provided by DHCP

Although the primary job of DHCP is to dole out IP addresses and subnet masks, DHCP actually provides more configuration information than just the IP address to its clients. The additional configuration information consists of DHCP options. The following is a list of some common DHCP options that can be configured by the server:

  • 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 operating systems 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. In the upcoming section, “Working with a DHCP Server,” I show you how to configure a DHCP server for Windows Server 2016. (The procedure for Windows Server 2012 and 2008 is similar.)

A server computer running DHCP doesn’t have to be devoted entirely to DHCP unless the network is very large. For most networks, a file server can share duty as a DHCP server. This is especially true if you provide long leases for your IP addresses. (Lease is the term 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. If you don’t want to burden one of your network servers with the DHCP function, you can enable the router’s built-in DHCP server. An advantage of allowing the router to be your network’s DHCP server is that you rarely need to power-down a router. In contrast, you occasionally need to restart or power-down a file server to perform system maintenance, apply upgrades, or perform troubleshooting.

tip 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 (known as scopes) for which each server is responsible. If you accidentally set up two DHCP servers for the same scope, you may end up with duplicate address assignments if the servers attempt to assign the same IP address to two different hosts. To prevent this from happening, just set up one DHCP server unless your network is so large that one server can’t handle the workload.

How DHCP actually works

You can configure and use DHCP without knowing the details of how DHCP client configuration actually works. However, a basic understanding of the process can help you to understand what DHCP is actually doing. Not only is this understanding enlightening, but it can also help when you’re troubleshooting DHCP problems.

The following paragraphs contain a blow-by-blow account of how DHCP configures TCP/IP hosts. This procedure happens every time you boot up a host computer. It also happens when you 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 a DHCP Discover message.

    This message uses the subnet’s broadcast address (all host ID bits set to one) as the destination address and 0.0.0.0 as the source address.

    tip The client has to specify 0.0.0.0 as the source address because it doesn't yet have an IP address, and it specifies the broadcast address as the destination address because it doesn’t know the address of any DHCP servers. In effect, the DHCP Discover message is saying, “Hey! I’m new here. Are there any DHCP servers out there?”

  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 the client can use.

    Like the DHCP Discover message, the DHCP Offer message is sent to the 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. In effect, the DHCP Offer message is saying, “Hello there, whoever you are. Here’s an IP address you can use, if you want it. Let me know.”

    What if the client never receives a DHCP Offer message from a DHCP server? In that case, the client waits for a few seconds and tries again. The client will try four times — at 2, 4, 8, and 16 seconds. If it still doesn’t get an offer, it will try again after five minutes.

  3. The client receives the DHCP Offer message and sends back a message known as a DHCP Request message.

    At this point, the client doesn’t actually own the IP address: It’s simply indicating that it’s ready to accept the IP address that was offered by the server. In effect, the DHCP Request message says, “Yes, that IP address would be good for me. Can I have it, please?”

  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.

    The DHCP Ack message says, in effect, “Okay, it’s all yours. Here’s the rest of the information you need to use it.”

  5. When the client receives the DHCP 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. In the simplest case, where a single DHCP server oversees IP configuration for an entire subnet, the scope corresponds to the subnet. However, if you set up two DHCP servers for a subnet, you can configure each with a scope that allocates only one part of the complete subnet range. In addition, a single DHCP server can serve more than one scope.

You must create a scope before you can enable a DHCP server. When you create a scope, you can provide it with the following properties:

Feeling excluded?

Everyone feels excluded once in awhile. With a wife, three daughters, and a female dog, I know how it feels. Sometimes, however, being excluded is a good thing. In the case of DHCP scopes, 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.

Here are a few reasons for excluding IP addresses from a scope:

  • The computer that runs the DHCP service itself must usually have a static IP address assignment. As a result, the address of the DHCP server should be listed as an exclusion.
  • Some hosts, such as a server or a 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.

Reservations suggested

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

  • TCP/IP configuration supplies more than just the IP address. If you 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 at the DHCP server, but also at each host that you configured statically.
  • You must remember to exclude the static IP address from the DHCP server’s scope. Otherwise, the DHCP server won’t know about the static address and may assign it to another host. Then, you’ll have two hosts with the same address on your network.

A better way to assign a fixed IP address to a particular host is to create a DHCP reservation. A reservation 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 the same address.

tip To create a reservation, you associate the IP address that you want assigned to the host with the host’s Media Access Control (MAC) address. As a result, you need to get the MAC address from the host before you create the reservation. You can get the MAC address by running the command ipconfig /all from a command prompt.

remember If you set up more than one DHCP server, each should be configured to serve a different range of IP addresses. Otherwise, the servers might assign the same address to two different hosts.

How long to lease?

One of the most important decisions that you’ll make when you configure a DHCP server is the length of time to specify for the lease duration. The default value is eight days, which is appropriate in many cases. However, you may encounter situations in which a longer or shorter interval may be appropriate:

  • The more stable your network, the longer the lease duration can safely exist. If you only periodically add new computers to the network or replace existing computers, you can safely increase the lease duration past eight days.
  • The more volatile the network, the shorter the lease duration should be. For example, a wireless network in a university library is used by students who bring their laptop computers into the library to work for a few hours at a time. For this network, a duration such as one hour may be appropriate.

warning Don’t configure your network to allow infinite duration leases. Some administrators feel that this cuts down the workload for the DHCP server on stable networks. However, no network is permanently stable. Whenever you find a DHCP server that’s configured with infinite leases, look at the active leases. I guarantee you’ll find IP leases assigned to computers that no longer exist.

Working with a DHCP Server

Usually, the best way to understand abstract concepts is to see how they work in the real world. To that end, the next few sections show you a brief overview of how DHCP is managed in a Windows network. First, you see how a DHCP server is installed in Windows Server 2016. Then you see how a DHCP server is configured.

Installing a Windows Server 2016 DHCP server

To install the DHCP server role on Windows Server 2016, follow these steps:

  1. Click Server Manager in the taskbar.

    The Server Manager application appears.

  2. Click Manage Roles & Features.

    The Before You Begin page of the Add Roles and Features Wizard appears.

  3. Click Next.

    The Installation Type page appears.

  4. Choose Role-Based or Feature-Based Installation and then click Next.

    The wizard displays a list of available servers.

  5. Select the server on which you want to install the DHCP role on; then click Next.

    The wizard displays a list of available server roles.

  6. Select DHCP Server from the list of roles and then click Next.

    The wizard displays a list of required features that must also be installed to support DHCP.

  7. Click Add Features, and then click Next.

    The wizard displays a page describing what the DHCP role entails.

  8. Click Next.

    The wizard displays a list of available server features; the features required to support the DHCP role are already selected.

  9. Click Next.

    The wizard displays a summary of what the DHCP role does.

  10. Click Next.

    The wizard displays a confirmation page.

  11. Click Install.

    The wizard installs the DHCP role, which may take a few minutes. When the installation completes, a results page is displayed to summarize the results of the installation.

  12. Click Close.

    You’re done!

Configuring a new scope

After you install the DHCP role on Windows Server 2016, you’ll need to create at least one scope so the server can start handing out IP addresses. Here are the steps:

  1. In Server Manager, choose Tools⇒  Serve

    This brings up the DHCP management console, shown in Figure 5-1.

  2. Select the DHCP server you want to define the scope for, click IPv4, and then click the New Scope button on the toolbar.

    This brings up the New Scope Wizard dialog box, as shown in Figure 5-2.

  3. Click Next.

    You’re prompted for the name of the scope, as shown in Figure 5-3.

  4. Enter a name and optional description, and then click Next.

    The wizard asks for information required to create the scope, as shown in Figure 5-4.

  5. Enter the information for the new scope.

    You must enter the following information:

    • Start IP Address: This is the lowest IP address that will be issued for this scope.
    • End IP Address: This is the highest IP address that will be issued for this scope.
    • Subnet Mask: This is the subnet mask issued for IP addresses in this scope.
  6. Click Next.

    The wizard asks whether you want to exclude any ranges from the scope range, as shown in Figure 5-5.

  7. (Optional) To create an exclusion, enter the IP address range to exclude and then click Add.

    You can repeat this step as many times as necessary to add any excluded addresses.

  8. Click Next.

    The wizard asks for the lease duration, as shown in Figure 5-6.

  9. (Optional) Change the lease duration; then click Next.

    When the wizard asks whether you want to configure additional DHCP options, leave this option set to Yes to complete your DHCP configuration now.

  10. Click Next.

    The wizard asks for the default gateway information, as shown in Figure 5-7.

  11. Enter the address of your network’s router and click Add; then click Next.

    The wizard now asks for additional DNS information, as shown in Figure 5-8.

  12. (Optional) If you want to add a DNS server, enter its address and then click Add.

    Repeat this step as many times as necessary to add any additional DNS servers.

  13. Click Next.

    The wizard next asks for WINS configuration information.

  14. (Optional) If you want to enable WINS, enter the WINS server configuration.

    WINS isn’t required for most modern networks, so you can usually just leave this page blank.

  15. Click Next.

    The wizard now asks whether you want to activate the scope.

  16. Select Yes, I Want to Activate This Scope and then click Next.

    A final confirmation page is displayed.

  17. Click Finish.

    The scope is created.

image

FIGURE 5-1: The DHCP management console.

image

FIGURE 5-2: The New Scope Wizard comes to life.

image

FIGURE 5-3: The wizard asks for a name for the new scope.

image

FIGURE 5-4: The wizard asks for scope information.

image

FIGURE 5-5: Do you want to create exclusions?

image

FIGURE 5-6: Set the lease duration.

image

FIGURE 5-7: Provide the Default Gateway address.

image

FIGURE 5-8: Provide additional DNS information.

How to Configure a Windows DHCP Client

Configuring a Windows client for DHCP is easy. The DHCP client is automatically included when you install the TCP/IP protocol, so all you have to do is configure TCP/IP to use DHCP. And in nearly all cases, DHCP is configured automatically when you install Windows.

If you must configure DHCP manually, bring up the Network Properties dialog box by choosing Network or Network Connections from Control Panel (depending on which version of Windows the client is running). Then, select the Internet Protocol Version 4 and click the Properties button. This brings up the dialog box shown in Figure 5-9. To configure the computer to use DHCP, select the Obtain an IP Address Automatically option and the Obtain DNS Server Address Automatically option.

image

FIGURE 5-9: Configuring a Windows client to use DHCP.

Automatic private IP addressing

If a Windows computer is configured to use DHCP but the computer can’t 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 that the address is unique on the network. As soon as the DHCP server becomes available, the computer requests a 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 its lease when the lease is halfway to the point of being expired. For example, if a client obtains an eight-day lease, it attempts to renew the lease after four days. However, you can renew a lease sooner by issuing the ipconfig /renew command at a command prompt. You may want to do this if you changed the scope's configuration or if the client’s IP configuration isn’t 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. This is shown in the output from the ipconfig /release command:

C:\>ipconfig /release

Windows IP Configuration

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :

IP Address… … … … : 0.0.0.0

Subnet Mask … … … . . : 0.0.0.0

Default Gateway … … … :

Here, you can see that the IP address and subnet masks are set to 0.0.0.0 and that the Default Gateway address is blank. When you release an IP lease, you can't communicate with the network by using TCP/IP until you issue an ipconfig /renew command to renew the IP configuration or restart the computer.