NetworkingDsc icon indicating copy to clipboard operation
NetworkingDsc copied to clipboard

xDnsServerAddress does not allow clearing of primary/secondary DNS Address

Open andy1547 opened this issue 7 years ago • 11 comments

Address has a ValidateNotNullOrEmpty attribute however it's a valid operation to clear it. If using DHCP then the manual address would be set back to automatic (just like the GUI). If using a static IP, then the manual addresses would be cleared.

andy1547 avatar May 17 '17 12:05 andy1547

When empty it should use the following cmdlet Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ResetServerAddresses This mimics the Windows UI functionality in that if DHCP is enabled DNS is set to automatic, if static IP is enabled the DNS is set to blank manual address (windows still technically classes this as automatic).

andy1547 avatar May 26 '17 07:05 andy1547

Hi @andy1547 - thanks for raising this!

I have battled with this problem for a while now and I've tried to sum up the problem in this issue: https://github.com/PowerShell/xNetworking/issues/113

I think it actually requires a change to the PowerShell cmdlets to expose whether or not DHCP is enabled on the DNS Client itself - which is currently not visible at all the PowerShell.

PlagueHO avatar May 29 '17 08:05 PlagueHO

Hi @andy1547 - I've completed the changes for this and am just waiting for a review to merge into the Dev branch. But if you're up for it you could test my version here: https://github.com/PlagueHO/xNetworking/tree/Issue-113

Thanks!

PlagueHO avatar Jun 03 '17 23:06 PlagueHO

@PlagueHO Having a skim over this it looks great so far, will hopefully get a chance to test some week sometime (deadlines are pretty tight over here). Thanks!

andy1547 avatar Jun 12 '17 13:06 andy1547

Thanks @andy1547 - this change has now been merged into Dev. So you can try it on the dev branch now.

PlagueHO avatar Jun 16 '17 22:06 PlagueHO

Will test this week, thanks @PlagueHO

andy1547 avatar Jun 19 '17 10:06 andy1547

Hi @andy1547 - did you get a chance to check this one? Did it work OK? If so, can we close this one?

PlagueHO avatar Jul 28 '17 21:07 PlagueHO

Sorry @PlagueHO been a busy free months!

Managed to test this today and worked as expected. Tested the standard use cases and the following edge cases with IPv4:

  • 3+ dns servers.
  • clearing the DNS servers both with DHCP enabled and disabled.

The only thing thing I noticed is an empty array is not permitted to clear the DNS servers, ideally an empty array would clear but null would leave as is.

Great work though, thanks!

andy1547 avatar Jul 30 '17 14:07 andy1547

Hi @andy1547 - sorry I forgot to respond to this one. But actually, it does look like we should be able to accept an empty array for Address. If you don't specify an Address parameter at all, internally it sets $Address to an empty array anyway. So I'll hold this open so we can consider making this enhancement. Thanks!

PlagueHO avatar Nov 04 '17 20:11 PlagueHO

If anyone else has the same problem to detect if the dns servers are static or from dhcp: netsh interface ipv4 show dns netsh interface ipv6 show dns there is no known other ("better") api, event wmi documentation does not state anything.

spali avatar Feb 13 '19 20:02 spali

When empty it should use the following cmdlet Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ResetServerAddresses This mimics the Windows UI functionality in that if DHCP is enabled DNS is set to automatic, if static IP is enabled the DNS is set to blank manual address (windows still technically classes this as automatic).

This functionality is available in DnsServerAddress.

@PlagueHO - I believe this issue can be closed.

phbits avatar Mar 24 '21 14:03 phbits