Monthly Archive

Categories

DHCP

DHCP scope

After rebuilding my test machine for Server 2016 (with mixed results) I needed to add a DHCP scope to the environment. I blogged about the DHCP PowerShell module several years ago.

 

To quickly add a DHCP scope to the current server

Add-DhcpServerv4Scope -Name 'Manticore Scope'  `
-StartRange 10.10.54.2 -EndRange 10.10.54.30 `
-Description 'Scope for Manticore domain' `
-Type DHCP -State Active -SubnetMask 255.255.255.0 `
-LeaseDuration (New-TimeSpan -Days 2)

 

Set-DhcpServerv4OptionValue  -ScopeId 10.10.54.0 -DnsServer 10.10.54.201

 

I’ll save this as I’ll have to rebuild the machine when Windows 2016 RTM’s and possibly again if I can’t get the wireless adapter to work then.

DHCP scope lease time

I wanted to reduce the lease time on a DHCP scope

 

$lt = New-TimeSpan -Hours 12
Set-DhcpServerv4Scope -ScopeId 10.10.54.0 -LeaseDuration $lt

 

You could even make it a one liner if you wished

 

Set-DhcpServerv4Scope -ScopeId 10.10.54.0 –LeaseDuration (New-TimeSpan -Hours 12)

Creating a DHCP reservation

For my demo at the PowerShell Summit I wanted to use DHCP for the Linux machine but guarantee that it had a specific IP address.  Time to create a DHCP reservation

 

The DHCP module in Windows Server 2012 and 2012 R2 enables you to create a reservation:

Add-DhcpServerv4Reservation -ScopeId 10.10.54.0 -IPAddress 10.10.54.2 -ClientId 00155D36C906 -Description "LInux machine" -Name "SphinxLX01"

 

The clientid is the VMs MAC address.

 

You can view the current reservations:

 

£> Get-DhcpServerv4Reservation -ScopeId 10.10.54.0 | fl *

IPAddress             : 10.10.54.2
ScopeId               : 10.10.54.0
AddressState          : ActiveReservation
ClientId              : 00-15-5d-36-c9-06
Description           : LInux machine
Name                  : SphinxLX01
Type                  : Both

 

You can view current leases:

£> Get-DhcpServerv4Lease -ScopeId 10.10.54.0 | fl *

IPAddress             : 10.10.54.2
ScopeId               : 10.10.54.0
AddressState          : ActiveReservation
ClientId              : 00-15-5d-36-c9-06
ClientType            : Dhcp
Description           : LInux machine
DnsRegistration       : NotApplicable
DnsRR                 : NoRegistration
HostName              : SphinxLX01
LeaseExpiryTime       :
NapCapable            : False
NapStatus             : FullAccess
PolicyName            :
ProbationEnds         :
ServerIP              : 10.10.54.201

 

And all from the comfort of your very own PowerShell prompt

Authorising a DHCP server and creating a scope

I recently re-built my test lab and now need to authorise the DHCP server.

You can test the DHCP server:

£> Get-DhcpServerSetting

IsDomainJoined            : True
IsAuthorized              : False
DynamicBootp              : True
RestoreStatus             : False
ConflictDetectionAttempts : 0
NpsUnreachableAction      : Full
NapEnabled                : False
ActivatePolicies          : True

Authorisation is straightforward

Add-DhcpServerInDC -DnsName server02.manticore.org -IPAddress 10.10.54.201

If you only have a single NIC in your DHCP server you don’t need to worry about the IP address

£> Get-DhcpServerSetting

IsDomainJoined            : True
IsAuthorized              : True
DynamicBootp              : True
RestoreStatus             : False
ConflictDetectionAttempts : 0
NpsUnreachableAction      : Full
NapEnabled                : False
ActivatePolicies          : True

Create a scope and activate it

Add-DhcpServerv4Scope -ComputerName server02 -Name "Manticore Scope"  -StartRange 10.10.54.2 -EndRange 10.10.54.30 -Description "Scope for Manticore domain" -Type DHCP -State Active -SubnetMask 255.255.255.0 -LeaseDuration (New-TimeSpan -Days 2)

ComputerName is the name of the DHCP server otherwise the parameters are self explanatory

To view all scopes

Get-DhcpServerv4Scope -ComputerName server02

To view specific scope

Get-DhcpServerv4Scope -ComputerName server02 -ScopeId 10.10.54.0 | fl

ScopeId          : 10.10.54.0
Name             : Manticore Scope
Description      : Scope for Manticore domain
SuperscopeName   :
SubnetMask       : 255.255.255.0
StartRange       : 10.10.54.2
EndRange         : 10.10.54.30
LeaseDuration    : 2.00:00:00
NapProfile       :
NapEnable        : False
Delay(ms)        : 0
State            : Active
Type             : Dhcp
MaxBootpClients  : 4294967295
ActivatePolicies : True

PowerShell 3 and DHCP: scope options

In this post - http://msmvps.com/blogs/richardsiddaway/archive/2011/09/23/powershell-3-and-dhcp-2-scopes.aspx - we created a new DHCP scope.

Now we need to set some options on the scope. One of the main options we need to set is the DNS server

We can see the available options using

Get-DhcpServerv4OptionDefinition -ComputerName server02

This displays a list of the available options – remember that we can add our own so this isn’t necessarily a static list

The options that are set for the test scope are

PS> Get-DhcpServerv4OptionValue -ComputerName server02 -ScopeId 192.168.100.0

OptionId   Name            Type       Value                VendorClass     UserClass       PolicyName
--------   ----            ----       -----                -----------     ---------       ----------
51         Lease           DWord      {86400}

The DNS server for this scope can be set like this

PS> Set-DhcpServerv4OptionValue -ComputerName server02 -ScopeId 192.168.100.0 `
-DnsServer 10.10.54.201

OptionId   Name            Type       Value                VendorClass     UserClass       PolicyName
--------   ----            ----       -----                -----------     ---------       ----------
6          DNS Servers     IPv4Add... {10.10.54.201}

PowerShell 3 and DHCP 2: scopes

In this post http://msmvps.com/blogs/richardsiddaway/archive/2011/09/20/powershell-and-dhcp-1-servers.aspx

I showed how we could discover DHCP server information

Scopes can be discovered

Get-DhcpServerv4Scope -ComputerName server02  -ScopeId 10.10.54.0

Now how do we create a scope?

We use Add-DhcpServerv4Scope. Now shouldn’t that have been New-DhcpServerv4Scope?

Never the less this is how it works

Add-DhcpServerv4Scope -ComputerName server02 -Name TestScope 
-StartRange 192.168.100.1 -EndRange 192.168.100.200
-Description "Scope for testing" -Type DHCP
-State Active -SubnetMask 255.255.255.0
-LeaseDuration (New-TimeSpan -Days 1)

Type can be Dhcp,Bootp or Both

State can be Active or InActive

This creates and activates the scope

To inactivate a scope

Set-DhcpServerv4Scope -ComputerName server02
-ScopeId 192.168.100.0
-State Inactive

To reactivate

Set-DhcpServerv4Scope -ComputerName server02
-ScopeId 192.168.100.0
-State Active

To create a reservation

Add-DhcpServerv4Reservation -ComputerName server02
-ScopeId 192.168.100.0 -IPAddress 192.168.100.190
-ClientId 00-01-02-03-04-05 -Name Test57 
-Description "Exclusion for test device"

The ClientId is the MAC address (this one is made up)

To view the scopes reservations

Get-DhcpServerv4Reservation -ComputerName server02 -ScopeId 192.168.100.0

To remove a reservation

Remove-DhcpServerv4Reservation -ComputerName server02
-ScopeId 192.168.100.0 -ClientId 00-01-02-03-04-05