This article describes how to migrate a configured DHCP server from one Windows Server host to another, while retaining all DHCP scope settings. You can use this guide to migrate DHCP settings, zones, and DHCP reservations from an earlier version of Windows Server to a newer version (for example, from Windows Server 2012/R2 to Windows Server 2022), or to move a DHCP role to a new host in Active Directory domain.
Table of Contents
Prepare New Windows Server Host for DHCP Role
Prepare a new host to which you are going to migrate the DHCP server. Install the version of Windows Server you need (2022, 2019, or 2016), set a unique host name and IP address, and join the computer to the Active Directory domain.
Install the DHCP Server host on the new server using the Server Manager console (Manage > Add Roles and Features > DHCP Server) or via PowerShell:
Add-WindowsFeature -IncludeManagementTools DHCP
Then run the following command, which will create two local security groups that will be used to manage DHCP server:
Add-DhcpServerSecurityGroup
- DHCP Administrators — these are users with full permissions on the DHCP server (they can change any settings), but without local admin permissions on Windows Server;
- DHCP Users — users with the rights to view DHCP server settings and statistics (including the DHCP Leases info).
Restart the DHCP Server service:
Restart-Service DHCPServer
Then authorize the new DHCP server in the Active Directory domain. Run the following command as the domain admin account that is a member of the Enterprise Admins group.
To authorize the new DHCP server in the Active Directory domain:
Add-DhcpServerInDC -DnsName host1.contoso.com -IPAddress 192.168.10.35
Replace the DnsName and IPAddress values with your own.
You can start a DHCP server without authorization in AD if you don’t have Enterprise Admin rights. Create the following registry parameter:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\DHCPServer\Parameters" -Name DisableRogueDetection -Value 1 -Force
To prevent the ‘Configuration required for DHCP server on host’ alert from being displayed in the Server Manager console, set the reg key to assume that the DHCP configuration is complete:
Set-ItemProperty –Path registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ServerManager\Roles\12 –Name ConfigurationState –Value 2
Then restart the DHCP service:
Restart-Service -Name DHCPServer -Force
Temporarily change the Lease duration (DHCP scope option) on the source server to 2 hours. This will allow your client to obtain IP addresses from the new DHCP server more quickly.
Transferring DHCP Server Role to Another Windows Server Host
The easiest way to transfer DHCP server settings to a new host in modern versions of Windows Server (2022/2019/2016/2012/R2) is to use the PowerShell cmdlets Export-DhcpServer and Import-DhcpServer.
These commands allow you to connect to a remote DHCP server over the network, export its settings and import them into a new server.
Create the C:\DHCP folder on the new DHCP server machine. Open the PowerShell console under an account that is a member of the DHCP Administrators group and export the configuration of the old DHCP server to the XML file:
Export-DhcpServer -ComputerName "oldDhcp.contoso.com" -Leases -File "C:\DHCP\OldDHCPConf.xml" –Verbose
Then import the resulting DHCP configuration file into your new server:
Import-DhcpServer -Leases –File "C:\DHCP\OldDHCPConf.xml" -BackupPath "C:\DHCP\Backup" –Verbose
Run the DHCP console and check that all the DHCP scopes, reservations, and IP leases are in place.
Once the DHCP server migration is complete, do not forget to reconfigure the DHCP Relay (IP Helper) agents on the routing network devices. Reconfigure them to point on the IP address of the new DHCP server.
Reboot several workstations to test and confirm that they are receiving DHCP leases from the new server (check the lease information for your DHCP scope).
How to Migrate the DHCP Role Using the Backup and Restore
In Windows Server 2016 and newer, you can migrate your DHCP server settings using the Backup and Restore options in the DHCP Management console GUI.
- Open dhcpmgmt.msc console;
- Right-click on the DHCP server and select Backup;
- Specify the directory to save the backup copy of the DHCP server settings.
You can use this backup copy to restore the DHCP server settings on the current or another Windows Server host. However, if you simply copy the DHCP backup files to a new server and try to restore the configuration using the Restore option in DHCP console, an error will occur when importing the DHCP database:
The database was not restored correctly. No changes were made. For more information, please see Event Viewer on the specified server.
To successfully migrate your DHCP server config to a new device, copy your DHCP backup to the %SystemRoot%\System32\DHCP\backup directory on a new machine. Then click the Restore option in the DHCP console and select to restore the configuration from this folder.
If everything was successful, the following message should appear:
The database was restored successfully.
Note that by default, Windows backs up the DHCP configuration and leases every 60 minutes to the %SystemRoot%\System32\DHCP\backup directory.
The backup directory is configured in the DHCP server settings.
You can list the current DHCP backup settings using the PowerShell command:
Get-DhcpServerDatabase
FileName : C:\Windows\system32\dhcp\dhcp.mdb
BackupPath : C:\Windows\system32\dhcp\backup
BackupInterval(m) : 60
CleanupInterval(m) : 60
LoggingEnabled : True
RestoreFromBackup : False
If your DHCP Windows Server host fails, you can manually copy the DHCP database files from the backup directory on the failed server’s disk and restore its configuration to the new server.
Migrate DHCP Server from Windows Server 2003
If you are using a legacy DHCP server on Windows Server 2003/R2, you need to use a different migration method. This is because Windows Server 2003 does not support the PowerShell cmdlets for exporting DHCP settings that are available in newer versions of Windows Server.
To export the DHCP server configuration to a binary file on Windows Server 2003, use the following command:
netsh dhcp server export C:\ps\dhcp2003_config.dat all
You can import the DHCP configuration on a new host using the command:
netsh dhcp server import \\winsrv2003dhcp\c$\ps\dhcp2003_config.dat all
DHCP Server Post Migration Steps
Change the lease duration settings on the new server if you have previously changed them. The default lease duration for the DHCP scope on Windows Server is 8 days.
Now you need to disable the DHCP service on the old server:
Stop-Service DHCPserver Set-Service -Name DHCPServer -StartupType "Disabled"
And unauthorize the old DHCP server from Active Directory from the DHCP console (right-click on the DHCP server name > Unauthorize)
Or use the PowerShell command:
Remove-DhcpServerInDC -DnsName "oldDhcp.contoso.com” -IPAddress 192.168.10.36
Then uninstall the DHCP Server Role:
Uninstall-windowsfeature dhcp -remove Uninstall-WindowsFeature RSAT-DHCP
And reboot the server:
Restart-Computer -Force
3 comments
On the import I get this.
PS C:\dhcp> Import-DhcpServer -Leases -File “C:\DHCP\OldDHCPConf.xml” -BackupPath “C:\DHCP\Backup” -Verbose
Get-DhcpServerVersion : Failed to get version of the DHCP server DC3.
At line:1 char:1
+ Get-DhcpServerVersion 2> $null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (DC3:root/Microsoft/…cpServerVersion) [Get-DhcpServerVersion], CimExcept
ion
+ FullyQualifiedErrorId : WIN32 1753,Get-DhcpServerVersion
Hi,
Thank you for this tutorial. Very helpful.
I just noticed, that on one command you are missing to backslashes:
Set-ItemProperty –Path registry::HKEY_LOCAL_MACHINE\SOFTWARE\MicrosoftServerManager\Roles12 –Name ConfigurationState –Value 2
Between Microsoft and ServerManager
Between Roles and 12
Cheers Till
Fantastic article. Thanks SO much! You made my DHCP migration to a new domain controller stress-free.
I missed the comment from Till, but I just manually did the DHCP configuration from Server Manager instead when the Set-ItemProperty command failed for me.
Comments are closed.