- Windows Server 2019 Cookbook
- Mark Henderson Jordan Krause
- 770字
- 2021-06-18 18:26:34
Creating a DHCP reservation for a specific server or resource
In a simple DHCP scope, any device that connects and asks for an IP address is handed whatever IP is next available within the scope. If you have a device that you always want to keep the same IP address for, you could manually configure the NIC properties with a static IP address. Otherwise, a more centralized way to assign a particular IP to the same device on a long-term basis is to use a DHCP reservation. Using a reservation in DHCP to assign an IP to a device makes a lot of sense because you can see that reservation right in the DHCP console, and you don't have to worry about keeping track of the static IP addresses that you have configured out in the field. Let's walk through configuring a quick reservation so that you are familiar with this process.
Getting ready
We will be using a Windows Server 2019 machine as our DHCP server where we will create the DHCP reservation. Additionally, we will use our WEB01 server as the recipient of this reservation by assigning WEB01 to IP address 172.16.97.84.
How to do it…
To create a DHCP reservation for a specific server or resource, perform these steps:
- Open the DHCP manager tool.
- Expand the left-hand pane down into the DHCP scope that we created earlier. Under this scope, you will see a folder called Reservations. Right-click on Reservations and click on New Reservation….
- Populate the fields. Your Reservation name field can contain anything descriptive. Fill out the IP address field with the IP address you want to reserve for this purpose. The last important piece of information is the MAC address field. This must be the MAC address of the device that you want to receive this particular IP address for. Since WEB01 is a Windows Server 2019 machine, we can get our MAC address by using Get-NetAdapter on WEB01:
- You can see MacAddress 00-15-5D-0F-05-28 in Command Prompt – this is our MAC address for WEB01. Use it to finish populating the DHCP reservation:
Tip
You can take your PowerShell to the next level here! Instead of highlighting and copying the MAC address, or even worse, typing it out by hand, try using (Get-NetAdapter).MacAddress | clip – it will copy your MAC address to your clipboard for you.
- Click on Add. You will see your new reservation listed in the DHCP management console.
- Now, make sure that the network on WEB01 is set to Obtain an IP address automatically. A quick PowerShell command to set this would be Set-NetIPInterface -InterfaceAlias 'Ethernet' -Dhcp Enabled. When WEB01 reaches out to DHCP to grab an IP address, it will now always receive 172.16.97.84 because of the reservation, rather than getting whatever IP address is next available within the DHCP scope.
- You can probably detect a pattern forming here when the PowerShell commands for this one. Again, it's the DHCPServer module and, this time, the Add-DhcpServerv4Reservation cmdlet:
Import-Module DHCPServer
Add-DhcpServerv4Reservation -IPAddress 172.16.97.84 -Name web01 -ClientId '00-15-5D-0F-05-28' -Description 'WEB01 Server' -ScopeId 172.16.97.50
How it works…
Typically, whenever a client computer is set to obtain an IP address automatically, it reaches out and looks for a DHCP server that hands to the client whatever IP address is free and next in the list. This may cause an IP address to change if the lease has expired and another device has taken its previous IP address. For desktop computers, this is usually fine. In some cases, however, it is beneficial to reserve particular IP addresses for specific devices, thereby ensuring they always receive the same IP address. The most common example of this that I have seen is a printer changing IP addresses after it's been turned off for a while, causing everyone in the office to be unable to print. Creating DHCP reservations is a good practice for static devices on the network, such as print server boxes and telephony equipment.
Tip
DHCP clients renew their lease when there is 50% of the lease time remaining. This means that for a 12-hour, lease they will renew after 6 hours. If unsuccessful, it will try again after 3 hours, then 90 minutes, then 45 minutes. Once the lease has expired, it will continue to try and refresh, requesting the same IP address it had before. However, there is no guarantee that it will receive the same IP address if, say, the DHCP server has reissued that IP to someone else in the meantime.