Backtrack:  
 
by lunarg on September 15th 2017, at 10:06

Sometimes it may become necessary to make changes to a DHCP scope on your Windows DHCP Server. Unfortunately, for existing scopes, not all scope options are editable, and it can become quite a hassle to recreate the scope, especially when there are a lot of reservations. Luckily, there's a workaround which allows you to edit the scope options, which is by using netsh.

It is not possible for netsh to directly edit scope options, but you can create a dump of the complete scope configuration (including all reservations), edit the resulting file, and import it back into the DHCP server. For this to work, you'll need admin (elevated) privileges on the DHCP server.

Notice
The procedure described below will clear the DHCP leases database as it cannot be exported using netsh. If the leases database is important, do not use this procedure!

First, determine which scope you want to make changes to. You'll need the scope subnet (something like "192.168.1.0" if your network is 192.168.1.0/24).

Next, start an elevated command prompt. As some temporary files will be created, you may want to "cd" to a temporary folder (e.g. C:\temp.

Dump the configuration of the scope using netsh:

netsh dhcp server scope 192.168.1.0 dump > scope.txt

This will dump the complete scope configuration to a file. As the output is plain text (it is in fact a netsh-script), you can make changes to that file, and thus, change anything in the scope using a text editor (e.g. Notepad).

Suppose you want to extend your subnet from 192.168.1.0/24 to 192.168.0.0/23, edit the file and make the following changes:

  • Do a search and replace for scope 192.168.1.0 and change all occurences to scope 192.168.0.0. This is necessary as extending your subnet from /24 to /23, means the first address is 192.168.0.1, resulting in the scope subnet to become 192.168.0.0.
    A good tool to determine this is IPCalc.
  • Change the subnet mask from 255.255.255.0 to 255.255.254.0. This can be done by editing the line:
    Dhcp Server \dhcp-server.mydomain add scope 192.168.1.0 255.255.255.0 "My DHCP Scope" ""
    Change it to:
    Dhcp Server \dhcp-server.mydomain add scope 192.168.0.0 255.255.254.0 "My DHCP Scope" ""

Before closing your editor, be sure to remove the first line of text (saying Changed the current scope context to x.x.x.x scope.), which is not part of the script. There's no way to filter this out during the dump, so it needs to be done manually. If not removed, the import will fail.

Once your file is ready, first remove the scope in the DHCP server (necessary as we will re-import the changed scope). Before doing so, if you're using DHCP failover, you should remove the failover partnership before removing the scope.

With the scope removed, you can now use netsh to re-import the file and recreate the scope, with the changed scope options, but with everything else intact (including a possibly long list of reservations):

netsh exec scope.txt

The scope will now be recreated, with the changes you made and with every other aspect of the scope (including reservations) intact. If you were using failover, recreate the failover partnership to your backup DHCP server.

 
 
« December 2024»
SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293031    
 
Links
 
Quote
« Most people tend to avoid true conflict. Ironically this breeds more conflict. »