Diberdayakan oleh Blogger.

Windows Server 2012 - DHCP - Part 2 - scope creation, Server and Scope options (command line)


Creation of scopes and options


 
Now let's set up a scope for our clients.
 
We will use the following settings for our first DHCP scope:
 
 
- The subnet mask is 255.0.0.0
 
- The default gateway is 10.1.1.2
 
- The DNS server is 10.1.1.10
 
- The domain name is machlinkit.biz
 
 
Note: the DHCP server's IP address is 10.1.1.10
 
 
 We'll start with PowerShell and then look at the results in the GUI. For reference, I will also present some of the equivalent NETSH commands. In Windows Server 2012, DHCP can be managed with Powershell alone but it may be useful to know a little NETSH, since we may still deal with Windows 2008 servers, or scripts containing the NETSH commands.


 
DHCP "Server Options"
 
 First, I want to configure the "Server Options" that, through inheritance, provide various information to clients in the scopes to be created. The most common information includes the default router IP address (option 3), the DNS server(s) IP address (option 6), and the domain name (option 15).

The settings in Server Options apply to all scopes by default. However, other settings can be applied at the scope level and would then take precedence over the settings inherited from Server Options. We'll see that later.


Here are the cmdlets that configure options 3, 6 and 15 (router, DNS server, domain name):
 
 
PS C:\> Set-DhcpServerv4OptionValue -OptionId 3 -value 10.1.1.2
 
PS C:\> Set-DhcpServerv4OptionValue -OptionId 6 -value 10.1.1.10
 
PS C:\> Set-DhcpServerv4OptionValue -OptionId 15 -value machlinkit.biz
 
 
 
We can verify the actual settings with the following PS commands:
 
PS C:\> Get-DhcpServerv4OptionValue -OptionId 3 | fl OptionID,Name,Value
 
OptionID : 3
 
Name : Router
 
Value : {10.1.1.2}
 
PS C:\> Get-DhcpServerv4OptionValue -OptionId 6 | fl OptionID,Name,Value
 
OptionID : 6
 
Name : DNS Servers
 
Value : {10.1.1.10}
 
PS C:\> Get-DhcpServerv4OptionValue -OptionId 15 | fl OptionID,Name,Value
 
OptionID : 15
 
Name : DNS Domain Name
 
Value : {machlinkit.biz}
 
 
 
Let's take a look at how the results would appear in DHCP Manager. Note that for those who prefer the GUI, here is where the settings would be edited.
 
So, we would configure Scope options here:
 
 
 
  
The following screenshots show where options 003, 006 and 015 are configured and then the results:
 
003 - Router
 
 
 
 
006 - DNS Server(S)
 
 
 
015 - Domain Name
 
 
 
This is how the results appear:
 
 
 
 
  
 
If needed, we can remove the options as follows:
 
PS C:\> Remove-DhcpServerv4OptionValue -OptionId 3
 
PS C:\> Remove-DhcpServerv4OptionValue -OptionId 6
 
PS C:\> Remove-DhcpServerv4OptionValue -OptionId 15
 
 
Have they been removed? Let's verify with option 003 (Router):
 
PS C:\> Get-DhcpServerv4OptionValue -OptionId 3 | fl OptionID,Name,Value
 
Get-DhcpServerv4OptionValue : Failed to get option value of 3 on DHCP server DC-001.
 
  
 Conclusion: the option is no longer present.
 
 
 
 
NETSH commands for Server Options
 
 
For reference, here are the equivalent NETSH commands:
 
 
PS C:\> netsh dhcp server set optionvalue 003 IPADDRESS 10.1.1.2
 
Command completed successfully.
 
PS C:\> netsh dhcp server set optionvalue 006 IPADDRESS 10.1.1.10
 
Server 10.1.1.10 is not a valid DNS Server.
 
Command completed successfully.
 
Note: the entry is not created - despite the "Command completed successfully." message. We may have to use the DhcpFullForce parameter:
 
PS C:\> netsh dhcp server set optionvalue 006 IPADDRESS DhcpFullForce 10.1.1.10
 
Command completed successfully.
 
PS C:\> netsh dhcp server set optionvalue 015 STRING machlinkit.biz
 
Command completed successfully.
 
 
 
 
 
Creation of scopes - and scope options
 
 
Now, let's create a scope with Powershell:
 
PS C:\> Add-DhcpServerv4Scope -Name MACH1 -StartRange 10.1.1.230 -EndRange 10.1.1.234 -SubnetMask 255.0.0.0
 
PS C:\>
 
The scope is activated automatically...
 
PS C:\> Get-DhcpServerv4Scope | fl
 
  • ScopeId : 10.0.0.0
  • Name : MACH1
  • SubnetMask : 255.0.0.0
  • StartRange : 10.1.1.230
  • EndRange : 10.1.1.234
  • LeaseDuration : 8.00:00:00
  • State : Active
  • Type : Dhcp
  • MaxBootpClients : 4294967295
  • ActivatePolicies : True
Note: blank values omitted for concision, bullets added.
 
Note that certain default values are used if no other parameters (and values) are specified after Add-DhcpServerv4Scope:
 
LeaseDuration : 8.00:00:00
 
---------------------------
---------------------------
 
 
Now let's look at a client machine. ipconfig /all shows (some values omitted for concision):
 
  • Physical Address. . . . . . . . . : 00-0C-29-F8-C0-46
  • DHCP Enabled. . . . . . . . . . . : Yes
  • Autoconfiguration Enabled . . . . : Yes
  • Link-local IPv6 Address . . . . . : fe80::e07e:50de:a86e:edc7%11(Preferred)
  • IPv4 Address. . . . . . . . . . . : 10.1.1.230(Preferred)
  • Subnet Mask . . . . . . . . . . . : 255.0.0.0
  • Lease Obtained. . . . . . . . . . : Saturday, October 05, 2015 11:14:21 AM
  • Lease Expires . . . . . . . . . . : Sunday, October 13, 2015 11:14:21 AM
  • Default Gateway . . . . . . . . . : 10.1.1.2
  • DHCP Server . . . . . . . . . . . : 10.1.1.10
  • DNS Servers . . . . . . . . . . . : 10.1.1.10
 
Note that even though settings such as "Default Gateway" or "DNS servers" were not configured for the scope itself, these settings are inherited from "Server Options".
 
If we configured settings for the scope, these scope settings would take precedence. I'll configure some test settings to illustrate this. Let's pretend the default gateway is 10.1.1.4.
 
 
Configuration of scope settings with PowerShell...
 
PS C:\> Set-DhcpServerv4OptionValue -ScopeID 10.0.0.0 -OptionId 3 -value 10.1.1.4
 
PS C:\> Get-DhcpServerv4Scope | fl
 
  • ScopeId : 10.0.0.0
  • Name : MACH1
  • SubnetMask : 255.0.0.0
  • StartRange : 10.1.1.230
  • EndRange : 10.1.1.234
  • LeaseDuration : 8.00:00:00
  • State : Active
  • Type : Dhcp
  • MaxBootpClients : 4294967295
  • ActivatePolicies : True
 
 
Note that the "Get-DhcpServerv4Scope" command does not show the scope options. We have to use these commands to view them:
 
 
PS C:\> Get-DhcpServerv4OptionValue -ScopeID 10.0.0.0 -OptionId 3 | fl
 
OptionId : 3
 
Name : Router
 
Type : IPv4Address
 
Value : {10.1.1.4}
 
PS C:\> Get-DhcpServerv4OptionValue -ScopeID 10.0.0.0 -OptionId 6 | fl
 
OptionId : 6
 
Name : DNS Servers
 
Type : IPv4Address
 
Value : {10.1.1.10}
 
PS C:\> Get-DhcpServerv4OptionValue -ScopeID 10.0.0.0 -OptionId 15 | fl
 
OptionId : 15
 
Name : DNS Domain Name
 
Type : String
 
Value : {machlinkit.biz}
 
 
On the client machine, we can see the new settings if we execute the ipconfig /renew command:
 
C:\>ipconfig /renew
 
C:\>ipconfig /all
 
[...]
 
IPv4 Address. . . . . . . . . . . : 10.1.1.230(Preferred)
 
Subnet Mask . . . . . . . . . . . : 255.0.0.0
 
Lease Obtained. . . . . . . . . . : Saturday, October 05, 2015 11:14:21 AM
 
Lease Expires . . . . . . . . . . : Sunday, October 13, 2015 11:45:35 AM
 
Default Gateway . . . . . . . . . : 10.1.1.4
 
DHCP Server . . . . . . . . . . . : 10.1.1.10
 
[...]
 
In DHCP Manager, the icons that represent settings inherited from Server Options and the icons that result from Scope Options are different:
 
 

  
If you attempt to edit settings inherited from Server Options, an error message like the one below will remind you that such an operation is not possible:
 
 
 
 
 
*
 
OK! My objective was to concentrate on DHCP configuration with Powershell but also show the equivalent operations in DHCP Manager and with NETSH. However, that's perhaps too ambitious for a single blog post (already quite long).
 
So... I'm going to suggest that those wanting to learn how to configure a scope (and scope options) in DHCP Manager consult the link below - which itself recommends that you simply follow the prompts of the DHCP Wizard...

 
 
 
As for the equivalent NETSH commands for scope creation, I will post them below in a sort of "annex".
 
As for exclusions and reservations, and perhaps other DHCP material, I will concentrate on those subjects in a later post.
 
*
 
Lastly, here is the "official" Microsoft reference to Powershell commands for DHCP:
 
 
 
 
***
 
Reference - NETSH commands for creating a scope - and scope options
 
 
Create a scope

PS C:\> netsh dhcp server add scope 192.168.1.0 255.255.255.0 BLDG1 "Building 1 subnet"


Add the IP address range to the scope

PS C:\> netsh dhcp server scope 192.168.1.0 add iprange 192.168.1.1 192.168.1.254

Command completed successfully.

PS C:\>

 

Thank you for reading the article about Windows Server 2012 - DHCP - Part 2 - scope creation, Server and Scope options (command line) on the blog NEW TECH If you want to disseminate this article on please list the link as the source, and if this article was helpful please bookmark this page in your web browser by pressing Ctrl + D on your keyboard keys.

New articles :