Export (0) Print
Expand All

Netsh DHCP example

Updated: January 21, 2005

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2

Netsh DHCP example

You can use Netsh commands for Dynamic Host Configuration Protocol (DHCP) in batch files and other scripts to automate tasks. The following example batch file demonstrates how to use Netsh commands for DHCP to perform a variety of related tasks.

In the circumstance of this example procedure, DHCP-01 is a DHCP server with the IP address The procedure adds a new scope to DHCP-01 with the name MyScope, IP address, subnet mask, and comment NewScope. It then configures the scope with an address range ( through, an exclusion range ( through, and router IP addresses (DHCP option 003). The scope is then set to an active state.

For more information, see Setting Up Scopes, Setting Up Options, and DHCP options.

For more information and a complete list of Netsh commands for DHCP, see Netsh commands for DHCP.

In the following example procedure, lines that contain comments are preceded by "rem," for remark. Netsh ignores comments.

rem one DHCP server:
rem (DHCP-01)

rem 1. Connect to (DHCP-01), and add the scope MyScope with IP address,
rem 1.1  subnet mask, and the comment NewScope.
netsh dhcp server add scope MyScope NewScope

rem 2. Connect to (DHCP-01 MyScope), and add IP address range to for distribution
rem 2.1  and the default ClientType of DHCP.
netsh dhcp server scope add iprange

rem 3. Connect to (DHCP-01 MyScope), and add IP exclusion range to
rem 3.1  and the default ClientType of DHCP.
netsh dhcp server scope add excluderange

rem 4. Connect to (DHCP-01 MyScope), and set the value of option code 003
rem 4.1   to list two router IP addresses (,
netsh dhcp server scope set optionvalue 003 IPADDRESS

rem 5.  Connect to (DHCP-01 MyScope), and set the scope state to active.
netsh dhcp server scope set state 1

rem 6. End example batch file.

The following table lists the netsh dhcp commands that are used in this example procedure.


Command Description


Shifts the current DHCP command-line context to the server that is specified by either its name or IP address.

add scope

Adds a new scope to the specified DHCP server.


Switches the command context to the DHCP scope that is specified by its IP address.

add iprange

Adds a range of IP addresses to the current scope.

add excluderange

Adds a range of excluded addresses to the current scope.

set optionvalue

Sets an option value for the current scope.

set state

Sets or resets the state of the current scope to either an active or inactive state.

Community Additions

© 2016 Microsoft