Windows Server

Scripting out DHCP reservations in Windows Server 2008 with Netsh

Scripting out DHCP reservations can save a lot of time for large pools of reservations. See how the Windows Server 2008 Netsh tool can help out in this regard.

Netsh is one of the most powerful Windows networking tools in the pre-PowerShell era. For Windows Server 2008, Netsh adds new contexts and expands some of the existing functionality introduced in Windows 2000.

One use of Netsh includes some management of DHCP scopes to modify reservations. An area in which this can be very useful is to script out a large batch of reservations for a number of virtual machines for a server subnet or a test scenario. On a Windows Server 2008 system running DHCP, this is the scripted out command to make or modify a reservation:

netsh dhcp server dc1 scope 192.168.1.0 add reservedip 192.168.1.189 080027C591F9 XVM1.WS2K8.DEV
In this example, the DHCP server name and scope are populated, as well as the desired IP address, the MAC address, and the DNS domain name of the system for the reservation. Once the command is entered, Netsh interacts with the DHCP service on the server to make the appropriate reservation to the scope. Figure A shows the command entered successfully. Figure A

Figure A

If an existing reservation needs modification, the existing entry should be sent a sequence of commands that delete the existing reservation and then add the new one. Here's an example:

netsh dhcp server dc1 scope 192.168.1.0 delete reservedip 192.168.1.189 080027C591F9
netsh dhcp server dc1 scope 192.168.1.0 add reservedip 192.168.1.181 080027C591F9

Netsh finesse can enable many tasks to be completed quickly. Plus, being able to modify many DHCP reservations in a scriptable fashion can save a lot of time during a large scope modification or creation.

For more about Netsh, check out my post: Creating port policies in Windows Server 2008 with Netsh.

Stay on top of the latest Windows Server 2003 and Windows Server 2008 tips and tricks with our free Windows Server newsletter, delivered each Wednesday. Automatically sign up today!

About

Rick Vanover is a software strategy specialist for Veeam Software, based in Columbus, Ohio. Rick has years of IT experience and focuses on virtualization, Windows-based server administration, and system hardware.

6 comments
arley
arley

I've been wanting the ability to script dhcp reservations for a long time, so I was really happy when I saw this post. But... on our W2K8R2 servers, netsh has only the dhcpclient context, no dhcp context. Any idea what is up with this?

b4real
b4real

Netsh is one of those tools that more you dig into it, the more power is revealed.

O & G IT Guy
O & G IT Guy

Des this functionality exist in NetSh before Windows 2008? Or is this new functionality?

b4real
b4real

Netsh was delivered starting with Windows 2000. Since then, it has gotten more and more robust, including adding new contexts. Without doublechecking, I ~~think~~ these commands in this context are new to WS2K8. Kinda like "the other PowerShell'

Editor's Picks