I wanted to share real quick how you set up and configure a DHCP server on Windows Server 2008 R2 or 2012 (R2) with he command line or powershell.
Windows Server 2008 R2:
Let’s begin with Windows Server 2008 R2, which doesn’t have any dhcp cmdlets in powershell so we have to mostly stick to the commandline.
To install the DHCP role, open an elevated powershell window:
Import-module ServerManager
Add-windowsfeature -Name DHCP
Note that the DHCP Server service is installed but stopped and disabled. Now we have to go to an elevated command prompt for the rest.To set the service to automatic startup and start the service.
sc config dhcpserver start= auto
net start dhcpserver
Authorize the server in AD:
netsh dhcp add server Server1.dhcplab.local 10.11.12.11
Create a scope, which is empty
netsh dhcp server add scope 10.11.12.0 255.255.255.0 "Scope1"
Add a range of IP addresses for leasing
netsh dhcp server scope 10.11.12.0 add iprange 10.11.12.101 10.11.12.200
Set the default gateway option
netsh dhcp server scope 10.11.12.0 set optionvalue 003 IPADDRESS 10.11.12.254
Set the lease time in seconds
netsh dhcp server scope 10.11.12.0 set optionvalue 51 DWORD 28800
Set the DNS server
netsh dhcp server scope 10.11.12.0 set optionvalue 006 IPADDRESS 10.11.12.1
Add a DHCP reservation, for a printer in this case
netsh dhcp server scope 10.11.12.0 add reservedip 10.11.12.190 A1B2C3D4E5F6 "Printer1" "Reservation for Printer1"
Windows Server 2012
Everything in an elevated powershell window. How sweet it is! 🙂
Install the DHCP Role (no need to configure the service afterwards)
add-windowsfeature -Name DHCP -includemanagementtools
Authorize the DHCP server
Add-DhcpServerInDC
Add scope with IP range for leasing
Add-DhcpServerv4Scope -Name "Scope2" -StartRange 10.11.12.101 -EndRange 10.11.12.200 -SubnetMask 255.255.255.0
Set lease duration (days.hours:minutes:seconds)
Set-DhcpServerv4Scope -ScopeId 10.11.12.0 -LeaseDuration 1.00:00:00
Set default gateway
Set-DhcpServerv4OptionValue -ScopeId 10.11.12.0 -Router 10.11.12.254
Set dns server and domain name
Set-DhcpServerv4OptionValue -DnsServer 10.11.12.1 -DnsDomain dhcplab.local
Set IP reservation, again for a printer
Add-DhcpServerv4Reservation -ScopeId 10.11.12.0 -IPAddress 10.11.12.190 -ClientId A1-B2-C3-D4-E5-F6 -Description "Reservation for Printer1" -Name "Printer1"