34,333
edits
Changes
New page: <table border="0" cellspacing="0" width="100%"> <tr> <td width="20%">Previous<td align="center">[[Windows Server 2008 R2 Essentials|Tabl...
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Configuring Windows Server 2008 R2 DHCP Servers|Previous]]<td align="center">[[Windows Server 2008 R2 Essentials|Table of Contents]]<td width="20%" align="right">[[Setting Up a Windows Server 2008 R2 Print Server|Next]]</td>
<tr>
<td width="20%">Configuring Windows Server 2008 DHCP Servers<td align="center"><td width="20%" align="right">Setting Up a Windows Server 2008 R2 Print Server</td>
</table>
<hr>
<google>BUY_WINSERV_2008R2</google>
The previous chapter (entitled [[Configuring Windows Server 2008 R2 DHCP Servers]]) provided an overview of running DHCP servers on Windows Server 2008 R2 systems and outlined the mechanisms for installing, configuring and maintaining DHCP using the graphical DHCP console. Windows Server 2008 R2 also provides the ability to perform a wide range of DHCP tasks directly from the command prompt using the '''netsh''' tool.
This chapter of [[Windows Server 2008 R2 Essentials]] will cover in the installation, configuration and management of DHCP on Windows Server 2008 from the command line.
== Installing the DHCP Feature from the Command Line ==
A Windows Server 2008 system can only act as a DHCP server if the DHCP feature has been installed. This can be achieved from the command prompt using the '''servermanagercmd''' utility as follows:
<pre>
servermanagercmd -install dhcp
</pre>
== Authorizing DHCP Servers in Active Directory ==
If a DHCP server is to operate within an Active Directory domain (and is not
running on a domain controller) it must first be authorized. This can be
achieved either as part of the DHCP Server role installation, or subsequently
using either DHCP console or at the command prompt using the '''netsh''' tool. To achieve this, open a command prompt and enter the following command:
<tt>netsh dhcp server ''serverID'' initiate auth</tt>
In the above command syntax, ''serverID'' is replaced by the IP address or
full UNC name of system on which the DHCP server is installed.
== Configuring Scopes at the Command Prompt ==
DHCP scopes may be configured from the command prompt using the netsh
tool. netsh may be run as a single command, or interactively. To run in interactive mode follow these steps:
1. At the command prompt enter netsh.
2. At the netsh> prompt enter dhcp.
3. At the netsh dhcp> prompt enter server \\servername where servername is the
UNC name or IP address of the server to be managed. For example:
<pre>
netsh dhcp>server \\winserver-1
</pre>
4. At the netsh dhcp server prompt, enter the commands to be executed.
Alternatively, run each netsh command separately, using the following syntax:
'''netsh dhcp server''' ''\\servername commands''
To create a new DHCP scope the command syntax is as follows:
'''netsh dhcp server''' ''\\servername'' '''scope''' ''subnetID'' '''add
iprange''' ''startIP endIP''
For example, to create a scope on subnet 192.168.2.0 ranging from 192.168.2.1
through 192.168.2.100:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 add iprange 192.168.2.1
192.168.2.100
Changed the current scope context to 192.168.2.0 scope.
Command completed successfully.
</pre>
To list a scope IP address range:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 show iprange
Changed the current scope context to 192.168.2.0 scope.
=========================================================
Start Address - End Address - Address type
=========================================================
192.168.2.1 - 192.168.2.100 - DHCP ONLY
Number of IP Ranges : 1 in the Scope : 192.168.2.0.
Command completed successfully.
</pre>
To delete a scope using netsh:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 delete iprange 192.168.2.1
192.168.2.100
Changed the current scope context to 192.168.2.0 scope.
Command completed successfully.
</pre>
To display the current state of a scope:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 show state
Changed the current scope context to 192.168.2.0 scope.
Current State of the Scope 192.168.2.0 : Active
Command completed successfully.
</pre>
To add an exclude range to a scope:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 add excluderange
192.168.2.10 192.168.2.20
Changed the current scope context to 192.168.2.0 scope.
Command completed successfully.
</pre>
To display an exclude ranges:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 show excluderange
Changed the current scope context to 192.168.2.0 scope.
=====================================
Start Address - End Address
=====================================
192.168.2.10 - 192.168.2.20
Number of ExcludeRanges : 1 in the Scope : 192.168.2.0.
Command completed successfully.
</pre>
To list the clients using a DHCP scope:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 show clients
Changed the current scope context to 192.168.2.0 scope.
Type : N - NONE, D - DHCP B - BOOTP, U - UNSPECIFIED, R - RESERVATION IP
==================================================================================
IP Address - Subnet Mask - Unique ID - Lease Expires -Type
==================================================================================
No of Clients(version 4): 0 in the Scope : 192.168.2.0.
Command completed successfully.
</pre>
== Activating and Deactivating DHCP Scopes using Netsh ==
<google>ADSDAQBOX_FLOW</google>
DHCP scopes must be activated before they can be used and may also be deactivated at any time. Both of these tasks may be performed at the command prompt using the ''netsh'' tool. For example, to activate a scope the following command line syntax is used:
'''netsh dhcp server''' ''serverID'' '''scope''' ''subnetID'' '''state''' ''status''
where ''serverID'' is the name or IP address of the computer running the DHCP server, ''subnetID'' is the network ID of the subnet on which the scope is to be configured, and ''status'' is either 1 or 0 depending on whether the scope is to activated (1) or deactivated (0). On a switched network with multiple virtual networks and hosts on a single network use 2 and 3 respectively to deactivate and activate the scope.
== Terminating a DHCP Lease using Netsh ==
The lease associated with an IP address may be terminated at the command prompt using the following command syntax:
'''netsh dhcp server''' ''serverID'' '''scope''' ''subnetID'' '''delete lease''' ''IPaddress''
where ''serverID'' is the name or IP address of the computer running the DHCP server, ''subnetID'' is the network ID of the subnet on which the IP address resides, and ''IPaddress'' is the IP address on which the lease is to be terminated. For example,
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 delete lease 192.168.2.101
</pre>
== Configuring DHCP Reservations using Netsh ==
DHCP reservations provide a mechanism by which IP addresses may be permanently
assigned to a specific client based on the MAC address of that client.
The MAC address of a Windows client can be found running the '''ipconfig /all''' command. For Linux systems the corresponding command is '''ifconfig -a'''. Once the MAC address has been identified, the reservation may be
configured using either the DHCP console or at the command prompt using the
'''netsh''' tool.
To add a reservation using '''netsh''' the following syntax is used:
'''netsh dhcp server''' \\''servername'' '''scope''' ''subnetID'' ''add reservedip'' ''IPaddress MacAddress ReservationName Comment''
For example the following command reserves an IP address for a specific MAC
address (note that the MAC address must be entered without any delimiters):
<pre>
C:\Users\Administrator>netsh dhcp server \\winserver-2 scope 192.168.2.0 add reservedip
192.168.2.12 0013720B1457 "CEO Printer" "Printer in Exec Suite"
Changed the current scope context to 192.168.2.0 scope.
Command completed successfully.
</pre>
To list the current reserved IP addresses for a particular scope the following
'''netsh''' command may be used:
<pre>
C:\Users\Administrator>netsh dhcp server \\winserver-2 scope 192.168.2.0 show
reservedip
Changed the current scope context to 192.168.2.0 scope.
===============================================================
Reservation Address - Unique ID
== Backing Up and Restoring DHCP Configuration Information ==
The current configuration of a DHCP server can quickly and easily be saved and restored using the '''dump''' option of the '''netsh''' tool. This enables a server to be quickly restored to its original state in the case of a system failure, or for the configuration to be duplicated on another server.
For example, to back up the configuration on a local server to a file named ''DHCPconfig.cfg'':
<pre>
netsh dhcp server dump > DHCPconfig.cfg
</pre>
The configuration on a remote system may be similarly saved by specifying the name or IP address of the server:
<pre>
netsh dhcp server winserver-1 dump > DHCPconfig.cfg
</pre>
The saved configuration may be restored by executing '''netsh''' with the '''exec''' option:
<pre>
netsh exec DHCPconfig.cfg
</pre>
== Configuring DHCP Conflict Detection ==
By default, if a DHCP server assigns an IP address to a client which conficts with another client, it is the job of the client to decline the assigned address and request that the DHCP server send another. A faster option is to enable ''DHCP Conflict Detection'' on the DHCP server, whereby the server checks that there are no conflicts associated with an IP address before it is assigned to a client. The DHCP server will repeat this process until a valid IP address is found, or a specified number of attempts to find a non-conflicting IP address is reached. The syntax to enable conflict detection and specify the number of retry attempts is as follows:
'''netsh dhcp server''' ''servername'' '''set detectionconflictretry''' ''no_of_attempts''
where ''servername'' is the name or IP address of the DHCP server and ''no_of_attempts'' is the maximum number of times the DHCP server will attempt to find a non-conflicting IP address. To disable conflict detection simply run the above command setting ''no_of_attempts'' to 0. For example:
<pre>
netsh dhcp server \\winserver-1 set detectionconflictretry 0
</pre>
== Backing Up and Restoring DHCP Configuration Information ==
The current configuration of a DHCP server can quickly and easily be saved and restored using the '''dump''' option of the '''netsh''' tool. This enables a server to be quickly restored to its original state in the case of a system failure, or for the configuration to be duplicated on another server.
For example, to back up the configuration on a local server to a file named ''DHCPconfig.cfg'':
<pre>
netsh dhcp server dump > DHCPconfig.cfg
</pre>
The configuration on a remote system may be similarly saved by specifying the name or IP address of the server:
<pre>
netsh dhcp server winserver-1 dump > DHCPconfig.cfg
</pre>
The saved configuration may be restored by executing '''netsh''' with the '''exec''' option:
<pre>
netsh exec DHCPconfig.cfg
</pre>
<google>BUY_WINSERV_2008R2</google>
<tr>
<td width="20%">[[Configuring Windows Server 2008 R2 DHCP Servers|Previous]]<td align="center">[[Windows Server 2008 R2 Essentials|Table of Contents]]<td width="20%" align="right">[[Setting Up a Windows Server 2008 R2 Print Server|Next]]</td>
<tr>
<td width="20%">Configuring Windows Server 2008 DHCP Servers<td align="center"><td width="20%" align="right">Setting Up a Windows Server 2008 R2 Print Server</td>
</table>
<hr>
<google>BUY_WINSERV_2008R2</google>
The previous chapter (entitled [[Configuring Windows Server 2008 R2 DHCP Servers]]) provided an overview of running DHCP servers on Windows Server 2008 R2 systems and outlined the mechanisms for installing, configuring and maintaining DHCP using the graphical DHCP console. Windows Server 2008 R2 also provides the ability to perform a wide range of DHCP tasks directly from the command prompt using the '''netsh''' tool.
This chapter of [[Windows Server 2008 R2 Essentials]] will cover in the installation, configuration and management of DHCP on Windows Server 2008 from the command line.
== Installing the DHCP Feature from the Command Line ==
A Windows Server 2008 system can only act as a DHCP server if the DHCP feature has been installed. This can be achieved from the command prompt using the '''servermanagercmd''' utility as follows:
<pre>
servermanagercmd -install dhcp
</pre>
== Authorizing DHCP Servers in Active Directory ==
If a DHCP server is to operate within an Active Directory domain (and is not
running on a domain controller) it must first be authorized. This can be
achieved either as part of the DHCP Server role installation, or subsequently
using either DHCP console or at the command prompt using the '''netsh''' tool. To achieve this, open a command prompt and enter the following command:
<tt>netsh dhcp server ''serverID'' initiate auth</tt>
In the above command syntax, ''serverID'' is replaced by the IP address or
full UNC name of system on which the DHCP server is installed.
== Configuring Scopes at the Command Prompt ==
DHCP scopes may be configured from the command prompt using the netsh
tool. netsh may be run as a single command, or interactively. To run in interactive mode follow these steps:
1. At the command prompt enter netsh.
2. At the netsh> prompt enter dhcp.
3. At the netsh dhcp> prompt enter server \\servername where servername is the
UNC name or IP address of the server to be managed. For example:
<pre>
netsh dhcp>server \\winserver-1
</pre>
4. At the netsh dhcp server prompt, enter the commands to be executed.
Alternatively, run each netsh command separately, using the following syntax:
'''netsh dhcp server''' ''\\servername commands''
To create a new DHCP scope the command syntax is as follows:
'''netsh dhcp server''' ''\\servername'' '''scope''' ''subnetID'' '''add
iprange''' ''startIP endIP''
For example, to create a scope on subnet 192.168.2.0 ranging from 192.168.2.1
through 192.168.2.100:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 add iprange 192.168.2.1
192.168.2.100
Changed the current scope context to 192.168.2.0 scope.
Command completed successfully.
</pre>
To list a scope IP address range:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 show iprange
Changed the current scope context to 192.168.2.0 scope.
=========================================================
Start Address - End Address - Address type
=========================================================
192.168.2.1 - 192.168.2.100 - DHCP ONLY
Number of IP Ranges : 1 in the Scope : 192.168.2.0.
Command completed successfully.
</pre>
To delete a scope using netsh:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 delete iprange 192.168.2.1
192.168.2.100
Changed the current scope context to 192.168.2.0 scope.
Command completed successfully.
</pre>
To display the current state of a scope:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 show state
Changed the current scope context to 192.168.2.0 scope.
Current State of the Scope 192.168.2.0 : Active
Command completed successfully.
</pre>
To add an exclude range to a scope:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 add excluderange
192.168.2.10 192.168.2.20
Changed the current scope context to 192.168.2.0 scope.
Command completed successfully.
</pre>
To display an exclude ranges:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 show excluderange
Changed the current scope context to 192.168.2.0 scope.
=====================================
Start Address - End Address
=====================================
192.168.2.10 - 192.168.2.20
Number of ExcludeRanges : 1 in the Scope : 192.168.2.0.
Command completed successfully.
</pre>
To list the clients using a DHCP scope:
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 show clients
Changed the current scope context to 192.168.2.0 scope.
Type : N - NONE, D - DHCP B - BOOTP, U - UNSPECIFIED, R - RESERVATION IP
==================================================================================
IP Address - Subnet Mask - Unique ID - Lease Expires -Type
==================================================================================
No of Clients(version 4): 0 in the Scope : 192.168.2.0.
Command completed successfully.
</pre>
== Activating and Deactivating DHCP Scopes using Netsh ==
<google>ADSDAQBOX_FLOW</google>
DHCP scopes must be activated before they can be used and may also be deactivated at any time. Both of these tasks may be performed at the command prompt using the ''netsh'' tool. For example, to activate a scope the following command line syntax is used:
'''netsh dhcp server''' ''serverID'' '''scope''' ''subnetID'' '''state''' ''status''
where ''serverID'' is the name or IP address of the computer running the DHCP server, ''subnetID'' is the network ID of the subnet on which the scope is to be configured, and ''status'' is either 1 or 0 depending on whether the scope is to activated (1) or deactivated (0). On a switched network with multiple virtual networks and hosts on a single network use 2 and 3 respectively to deactivate and activate the scope.
== Terminating a DHCP Lease using Netsh ==
The lease associated with an IP address may be terminated at the command prompt using the following command syntax:
'''netsh dhcp server''' ''serverID'' '''scope''' ''subnetID'' '''delete lease''' ''IPaddress''
where ''serverID'' is the name or IP address of the computer running the DHCP server, ''subnetID'' is the network ID of the subnet on which the IP address resides, and ''IPaddress'' is the IP address on which the lease is to be terminated. For example,
<pre>
netsh dhcp server \\winserver-1 scope 192.168.2.0 delete lease 192.168.2.101
</pre>
== Configuring DHCP Reservations using Netsh ==
DHCP reservations provide a mechanism by which IP addresses may be permanently
assigned to a specific client based on the MAC address of that client.
The MAC address of a Windows client can be found running the '''ipconfig /all''' command. For Linux systems the corresponding command is '''ifconfig -a'''. Once the MAC address has been identified, the reservation may be
configured using either the DHCP console or at the command prompt using the
'''netsh''' tool.
To add a reservation using '''netsh''' the following syntax is used:
'''netsh dhcp server''' \\''servername'' '''scope''' ''subnetID'' ''add reservedip'' ''IPaddress MacAddress ReservationName Comment''
For example the following command reserves an IP address for a specific MAC
address (note that the MAC address must be entered without any delimiters):
<pre>
C:\Users\Administrator>netsh dhcp server \\winserver-2 scope 192.168.2.0 add reservedip
192.168.2.12 0013720B1457 "CEO Printer" "Printer in Exec Suite"
Changed the current scope context to 192.168.2.0 scope.
Command completed successfully.
</pre>
To list the current reserved IP addresses for a particular scope the following
'''netsh''' command may be used:
<pre>
C:\Users\Administrator>netsh dhcp server \\winserver-2 scope 192.168.2.0 show
reservedip
Changed the current scope context to 192.168.2.0 scope.
===============================================================
Reservation Address - Unique ID
== Backing Up and Restoring DHCP Configuration Information ==
The current configuration of a DHCP server can quickly and easily be saved and restored using the '''dump''' option of the '''netsh''' tool. This enables a server to be quickly restored to its original state in the case of a system failure, or for the configuration to be duplicated on another server.
For example, to back up the configuration on a local server to a file named ''DHCPconfig.cfg'':
<pre>
netsh dhcp server dump > DHCPconfig.cfg
</pre>
The configuration on a remote system may be similarly saved by specifying the name or IP address of the server:
<pre>
netsh dhcp server winserver-1 dump > DHCPconfig.cfg
</pre>
The saved configuration may be restored by executing '''netsh''' with the '''exec''' option:
<pre>
netsh exec DHCPconfig.cfg
</pre>
== Configuring DHCP Conflict Detection ==
By default, if a DHCP server assigns an IP address to a client which conficts with another client, it is the job of the client to decline the assigned address and request that the DHCP server send another. A faster option is to enable ''DHCP Conflict Detection'' on the DHCP server, whereby the server checks that there are no conflicts associated with an IP address before it is assigned to a client. The DHCP server will repeat this process until a valid IP address is found, or a specified number of attempts to find a non-conflicting IP address is reached. The syntax to enable conflict detection and specify the number of retry attempts is as follows:
'''netsh dhcp server''' ''servername'' '''set detectionconflictretry''' ''no_of_attempts''
where ''servername'' is the name or IP address of the DHCP server and ''no_of_attempts'' is the maximum number of times the DHCP server will attempt to find a non-conflicting IP address. To disable conflict detection simply run the above command setting ''no_of_attempts'' to 0. For example:
<pre>
netsh dhcp server \\winserver-1 set detectionconflictretry 0
</pre>
== Backing Up and Restoring DHCP Configuration Information ==
The current configuration of a DHCP server can quickly and easily be saved and restored using the '''dump''' option of the '''netsh''' tool. This enables a server to be quickly restored to its original state in the case of a system failure, or for the configuration to be duplicated on another server.
For example, to back up the configuration on a local server to a file named ''DHCPconfig.cfg'':
<pre>
netsh dhcp server dump > DHCPconfig.cfg
</pre>
The configuration on a remote system may be similarly saved by specifying the name or IP address of the server:
<pre>
netsh dhcp server winserver-1 dump > DHCPconfig.cfg
</pre>
The saved configuration may be restored by executing '''netsh''' with the '''exec''' option:
<pre>
netsh exec DHCPconfig.cfg
</pre>
<google>BUY_WINSERV_2008R2</google>