question

ErazerMe avatar image
0 Votes"
ErazerMe asked ErazerMe commented

DHCP-Option 12 missing after DHCP-Server restart

We are using DHCP-Reservation to provide an IP-adress to our clients. Additional we use the DHCP-Option 12 to handle the Hostname of the client.

The DHCP-reservation (including the option12) were set within a powershell script to decrease the manual tasks.
We noticed, that the DHCP-Option 12 of IP-Reservation (which was set with the command "Set-DhcpServerv4OptionValue") will be resetted after a restart of the DHCP-Server.
Note: when you do this step manually within the GUI, the problem does not occure.

Summarized: setting the option 12 to a DHCP-Reservation with command "Set-DhcpServerv4OptionValue", will be resetted after restarting the DHCP-Services.
Can anyone provide me a workaround or does anyone have a idea how I can solve the issue?


Attached you can find a short Powershell-Snippet which you can use to reproduce the problem:

Blockquote
#Ensure that you have a IP-Scope with 192.168.10.0
$ipscope = "192.168.10.0"
$ipscope_start = "192.168.10.1"
$ipscope_end = "192.168.10.254"
$ipscope_subnetmask = "255.255.255.0"
[ipaddress]$ip = "192.168.10.18" #Mention your IP-Adress you want to test
$DHCPServer = "TEMPLATE_W2K16" #Mention the Servername of your testserver

Add-DhcpServerv4Scope -ComputerName $DHCPServer -StartRange $ipscope_start -EndRange $ipscope_end -Name $ipscope -SubnetMask $ipscope_subnetmask
Add-DhcpServerv4Reservation -ComputerName $DHCPServer -ScopeId $ipscope -IPAddress $ip -ClientId "11-22-33-44-55-66" -Name "Initialname"

For($i=0; $i -le 5;$i++)
{
$reservationname = "Name$i"
Set-DhcpServerv4Reservation -IpAddress $ip -ClientId 11-22-33-44-55-66 -Name $reservationname -Description $reservationname -Type Dhcp -ComputerName $DHCPServer
Set-DhcpServerv4OptionValue -ReservedIP $ip -OptionId 12 -Value $reservationname -ComputerName $DHCPServer
$OptionValue1 = Get-DhcpServerv4OptionValue -ReservedIP $Ip -ComputerName $DHCPServer
Write-host "Current Option: $($OptionValue1.Value)"
Read-host "Restart DHCP-Service?"
Restart-Service DHCPServer
sleep -Seconds 5
$OptionValue2 = Get-DhcpServerv4OptionValue -ReservedIP $Ip -ComputerName $DHCPServer
Write-Host "Option12 we want to set: $reservationname"
Write-host "Option12 after restart: $($OptionValue2.Value)"
Read-host "Next try?"
}

windows-serverwindows-server-powershellwindows-server-2016windows-dhcp-dns
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered ErazerMe commented

Well, that is just bonkers! The value changes in the MMC but it's lost after restarting the service. Looks like a bug to me!

You can try this as a work-around. The Remove-DhcpServerv4OptionValue will fail in the 1st iteration because I didn't bother to set it outside the loop, but it's just a demo so don't let it bother you:

 #Ensure that you have a IP-Scope with 192.168.10.0
 $ipscope = "192.168.10.0"
 $ipscope_start = "192.168.10.1"
 $ipscope_end = "192.168.10.254"
 $ipscope_subnetmask = "255.255.255.0"
 [ipaddress]$ip = "192.168.10.18" #Mention your IP-Adress you want to test
 $DHCPServer = "SRV02" #Mention the Servername of your testserver
    
 Add-DhcpServerv4Scope -ComputerName $DHCPServer -StartRange $ipscope_start -EndRange $ipscope_end -Name $ipscope -SubnetMask $ipscope_subnetmask
 Add-DhcpServerv4Reservation -ComputerName $DHCPServer -ScopeId $ipscope -IPAddress $ip -ClientId "11-22-33-44-55-66" -Name "Initialname"
    
 For ($i = 0; $i -le 5; $i++) {
     Remove-DhcpServerv4OptionValue -ComputerName $DHCPServer -OptionID 12 -ReservedIP $ip
     Remove-DhcpServerv4Reservation -ComputerName $DHCPServer -ReservedIP $IP
    
     $reservationname = "Name$i"
    
     Add-DhcpServerv4Reservation -ComputerName $DHCPServer -ScopeId $ipscope -IPAddress $ip -ClientId "11-22-33-44-55-66" -Name $reservationname -Description $reservationname -Type Dhcp
     Set-DhcpServerv4OptionValue -ReservedIP $ip -OptionId 12 -Value $reservationname -ComputerName $DHCPServer
    
     $OptionValue1 = Get-DhcpServerv4OptionValue -ReservedIP $Ip -ComputerName $DHCPServer  # may return options 12 and 81
     Write-Host "Current Option: $($OptionValue1.Value)"
     Read-Host "Restart DHCP-Service?"
     Restart-Service DHCPServer
     sleep -Seconds 5
     $OptionValue2 = Get-DhcpServerv4OptionValue -ReservedIP $Ip -ComputerName $DHCPServer
     Write-Host "Option12 we want to set: $reservationname"
     Write-Host "Option12 after restart: $($OptionValue2.Value)"
     Read-Host "Next try?"
 }
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JYes, that's really crazy.
I have tested the behaviour: It is even enough, if you use "Remove-DHCPServerv4OptionValue" before you add a new value (with "Set-DHCPServerv4OptionValue").

The curious thing is, that the change is visibile within the MMC/GUI and really available - but after restarting the DHCP-Service the value is changed back.

In my opinion, this is a real bug.
Normally a "set-"command also has to update the existing value.
I have already a ticket opened to microsoft - they investigate the issue if it's a bug or not.
They have been investigating this for 8 weeks now.

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered ErazerMe commented

Add some error handling around that option value setting:

 Try{
     Set-DhcpServerv4OptionValue -ReservedIP $ip -OptionId 12 -Value $reservationname -ComputerName $DHCPServer -ErrorAction STOP
 }
 Catch{
     Throw $_
 }

The setting of the option value requires that the option has already been defined, but I don't see that in your code (Set-DhcpServerv4OptionDefinition).
From the help for the Set-DhcpServerv4OptionValue cmdlet: "The definition for the option must already exist."

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @RichMatheisen-8856,

yes, the optiondefinition is set before, because 'Option 12' is a default option of a Windows DHCP-Server.

Additional, the 'try/catch' will also not work, because the option12 is set to the DHCP-reservation and can also be reviewed, BUT: after restarting the DHCP-Service, the value is gone.

0 Votes 0 ·
SunnyQi-MSFT avatar image
0 Votes"
SunnyQi-MSFT answered ErazerMe commented

Hi,

Thanks for posting in Q&A platform.

I will reproduce this issue in my environment and keep you posted if any update.

Please try to configure this Option 12 from GUI and restart to see if the issue still existed.

Best Regards,
Sunny


If the Answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hey,

I already tested the behaviour when I do that within the GUI - then all works fine and also after restarting the DHCP-Service all looks good.
So the problem is only while pushing the option with the powershell-command - doing all the tasks manually is not possible in our enviroment.

0 Votes 0 ·