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.
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:
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.
« ‹ | November 2024 | › » | ||||
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |