Subscribe to Windows IT Pro
May 08, 2006 12:00 AM

Create DHCP Scopes

Use the Windows 2003 Netsh command to change network settings
Windows IT Pro
InstantDoc ID #49862
Rating: (2)
Downloads
49862.zip

The command to exclude an IP range is similar to setting the IP range for a particular DHCP scope. For example, the command

Netsh dhcp server 
  \\mydhcpserver 
  scope 192.168.100.0 
  add excluderange 192.168.100.1 
  192.168.100.10 

would exclude any IP address from 192.168.100.1 through 192.168.100.10 from being assigned by the DHCP server named mydhcpserver. It's important to note that the exclusion range must fall within the IP inclusion range you set earlier because you're only excluding a subset of IP addresses within the IP range for that scope.

A sample command for creating a DHCP reservation is:

Netsh dhcp server
  \\mydhcpserver 
  scope 192.168.100.0 
  add reservedip 192.168.100.2 
  00433FBB0023 
  printerA "test printer" BOTH 

This sample command would reserve the IP address 192.168.100.2 for the node with the MAC address 00433FBB 0023. It gives the reservation the name printerA and the comment test printer. BOTH is the client type, indicating that the reservation should work for both DHCP and BOOTP client requests.

Making the Script Work
The CreateDHCPScope script must be executed from a Windows 2003 server due to its dependence on the Netsh dhcp command. It's important to note that the script does no error checking to verify that the scope was created successfully, so I highly recommend that you verify in the DHCP snap-in that the scope you specified when running the script was created successfully. Typically, if the script is unsuccessful in creating a scope, it's because the operator provided an incorrect subnet mask for the network ID of the scope.

As you can see, just a few lines of code can make it much easier to manage your DHCP environment. You can take this code and expand it for your own purposes. For example, for every scope created, a script could create a certain number of "dummy" reservations to accommodate any reservations that might be necessary in the future, such as if a new printer is added to the subnet. You can also back up and migrate DHCP scopes by using the Netsh dhcp export and import subcommands.

Related Content:

ARTICLE TOOLS

Comments
  • bill
    4 years ago
    Apr 11, 2008

    netsh add helper dhcpmon.dll

  • ROb
    5 years ago
    Sep 27, 2007

    I always like articles like this, which usually remind of things I've forgotten about, or turn me on to new ways to automate.

    In the case of NETSH for DHCP configuration, I always see one ommission regarding using this commandline tool for scripting DHCP configuration, and it can be confounding until you realize what's happening: You cannot configure remote DHCP servers with NETSH unless you have the DHCP service installed locally. In other words, if you try to use NETSH to get to the DHCP configuration commands for a remote server from an XP workstation, the DHCP subset of commands is not available. And if you are on a server without DHCP installed, the commands will also not be available.

    Many admins (like myself) install all available Microsoft support tools and ResKit tools, but none of that matters (in this case) if you don't have Microsoft DHCP service installed locally.

    If there's some DLL that can be registered to alleviate this, I'd love to hear about it.

    -- Rob "I" --
    Sr Windows Admin

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.