The Dynamic Host Configuration Protocol (DHCP) is a foundational network service in any Windows Server environment. While the Server Manager GUI is perfectly adequate for setting up a single server, administrators managing multiple branch offices or deploying infrastructure as code rely on PowerShell to automate the installation and configuration of DHCP. This guide demonstrates how to provision a complete DHCP server using command-line cmdlets.
Step 1: Install the DHCP Server Role
First, you must install the DHCP Server role binaries and the associated management tools on the server.
Open an elevated PowerShell prompt and run:
Install-WindowsFeature -Name DHCP -IncludeManagementTools
Once the installation is complete, the DHCP service is present but not yet authorized or configured.
Step 2: Authorize the DHCP Server in Active Directory
If your server is part of an Active Directory domain, it will not lease IP addresses until it is explicitly authorized. This security feature prevents rogue DHCP servers from hijacking network traffic.
To authorize the server, run the following command, replacing the placeholders with your server’s fully qualified domain name (FQDN) and its static IP address:
Add-DhcpServerInDC -DnsName "dhcp01.corp.example.com" -IPAddress 192.168.1.10
Step 3: Create a DHCP Scope
A DHCP scope is the pool of IP addresses that the server is allowed to distribute to clients. You must define the starting IP, ending IP, subnet mask, and a descriptive name.
Add-DhcpServerv4Scope -Name "HQ_Office_Subnet" -StartRange 192.168.1.100 -EndRange 192.168.1.200 -SubnetMask 255.255.255.0 -State Active
This command creates an active scope that will lease 101 IP addresses (from .100 to .200).
Step 4: Configure Scope Options (DNS and Gateway)
A client machine needs more than just an IP address; it needs to know where the router is (the Default Gateway) and how to resolve hostnames (DNS Servers). These are configured as DHCP Options.
- Option 003: Default Gateway (Router)
- Option 006: DNS Servers
- Option 015: DNS Domain Name
Apply these options to the scope you just created using the Set-DhcpServerv4OptionValue cmdlet:
Set-DhcpServerv4OptionValue -ScopeId 192.168.1.0 -Router 192.168.1.1 -DnsServer 192.168.1.10,192.168.1.11 -DnsDomain "corp.example.com"
Note: The -ScopeId is always the network address of the subnet (e.g., ending in .0).
Step 5: Verify the Configuration
You can quickly verify that your scope and options were created successfully by running:
Get-DhcpServerv4Scope
Get-DhcpServerv4OptionValue -ScopeId 192.168.1.0
Your Windows Server is now fully configured and actively listening for DHCP discover broadcasts from client devices on the network.