NetworkingDsc
NetworkingDsc copied to clipboard
xDefaultGateWayAddress: GateWay address not set in certain DHCP scenarios
Details of the scenario: The default gateway address may not be set if DHCP is currently assigning the same address you are trying to set statically. For example, if DHCP is handing you "10.10.10.1" for your default gateway address and you configure xDefaultGateWayAddress to configure "10.10.10.1" as the statically defined gateway, DSC detects that the gateway is already set to the desired state and makes no changes. This results in a successfully applied configuration, but a network interface that will not respond.
VERBOSE: [server]: [[xDefaultGatewayAddress]SetGatewayData] Test-TargetResource: Checking the Default Gateway Address. VERBOSE: [server]: [[xDefaultGatewayAddress]SetGatewayData] Test-TargetResource: Default gateway is correct. VERBOSE: [server]: LCM: [ End Test ] [[xDefaultGatewayAddress]SetGatewayData] in 2.4660 seconds.
The DSC configuration that is using the resource: `
xNetAdapterName DeviceNameData
{
NewName = 'Data'
Interfacedescription = 'vmxnet3 Ethernet Adapter'
}
xDefaultGateWayAddress SetGatewayData
{
Address = $node.gatewaydata
InterfaceAlias = 'Data'
AddressFamily = 'IPv4'
DependsOn = '[xIPAddress]NewIPv4AddressData'
}
xDnsServerAddress DnsServerAddressData
{
Address = $node.DNSServers
InterfaceAlias = 'Data'
AddressFamily = 'IPv4'
Validate = $true
DependsOn = '[xNetAdapterName]DeviceNameData'
}
xDhcpClient DisabledDhcpClientData
{
State = 'Disabled'
InterfaceAlias = 'Data'
AddressFamily = 'IPv4'
DependsOn = '[xNetAdapterName]DeviceNameData'
}
xIPAddress NewIPv4AddressData
{
IPAddress = $node.IPAddressData
InterfaceAlias = 'Data'
AddressFamily = 'IPV4'
DependsOn = '[xDhcpClient]DisabledDhcpClientData'
}
` Version of the Operating System and PowerShell the DSC Target Node is running: Windows Server 2016, Windows PowerShell 5.1.14393.1532 Version of the DSC module you're using, or 'dev' if you're using current dev branch: xNetworking 5.7.0.0
Hi @SinnGit - does it make a difference if you apply the move the DhcpClient part to the top of the configuration to ensure the DHCP is disabled before setting the Default Gateway?
Hi @PlagueHO , thanks for the reply. Looks like reordering the configuration did the trick. I had previously attempted this by using the "DependOn" option as noted in the configuration in my original post, and although I could actually watch the verbose output applying the resources in the intended order, the gateway setting still would not stick. Good lesson moving forward I guess, although "dependson" can change when a resource runs, it still matters how resources are ordered within the configuration.
Here's my current config that works to properly set the default gateway. Note that in this configuration I am applying the DNS servers last, I have the same issue with this resource, the DNS servers are not set in this configuration. Looks like you will want to properly order the resource to disable DHCP to have it above any other resources that may set static networking options.
Configuration AdminJump
{
Param
(
[Parameter(Mandatory=$true)]
[pscredential]$DNSCredential
)
Import-DscResource -ModuleName xnetworking
Node $AllNodes.NodeName
{
$CertificateFile = "\\server\share\Certs\DSCPush\$($node.NodeName).cer"
LocalConfigurationManager
{
CertificateId = $node.thumbprint
RebootNodeIfNeeded = $true
ConfigurationMode = 'ApplyOnly'
}
#region IP Settings
xNetAdapterName DeviceNameData
{
NewName = 'Data'
Interfacedescription = 'vmxnet3 Ethernet Adapter'
}
xDhcpClient DisabledDhcpClientData
{
State = 'Disabled'
InterfaceAlias = 'Data'
AddressFamily = 'IPv4'
DependsOn = '[xNetAdapterName]DeviceNameData'
}
xIPAddress NewIPv4AddressData
{
IPAddress = $node.IPAddressData
InterfaceAlias = 'Data'
AddressFamily = 'IPV4'
DependsOn = '[xDhcpClient]DisabledDhcpClientData'
}
xDefaultGateWayAddress SetGatewayData
{
Address = $node.gatewaydata
InterfaceAlias = 'Data'
AddressFamily = 'IPv4'
DependsOn = '[xIPAddress]NewIPv4AddressData'
}
xDnsServerAddress DnsServerAddressData
{
Address = $node.DNSServers
InterfaceAlias = 'Data'
AddressFamily = 'IPv4'
Validate = $true
DependsOn = '[xNetAdapterName]DeviceNameData'
}
#endregion
}
}
Thanks for the assistance!
Cool - no problem @SinnGit ! Happy to help!
Why was this issue closed? This behavior certainly doesn't seem right being that DependsOn should take precedence over the physical order of the items in the template.
Also, it should at the very least be documented that these are order dependent. It isn't clear at all which order the construction of these settings should go, and I probably wouldn't have gotten it if I didn't search for this issue.
Hi @NightOwl888 - I've reopened this issue.
There are some existing examples on how you would normally configure a static IP address. But we could probably use some additional ones showing some more in-depth examples. So I've reopened this to make sure we add some new examples and documentation.
FWIW, I don't actually generally use the DHCPClient resource at all in my configs - I just set the IPAddress, DefaultGateWayAddress and DnsServerAddress.
E.g. an example of one of my Networking configs - I never use the DHCPClient resource if I'm setting a static IP on the adapter:
Configuration Networking {
Import-DscResource -ModuleName NetworkingDsc -ModuleVersion 6.2.0.0
IPAddress IPv4_2 {
InterfaceAlias = 'LABBUILDER-DCANDDHCPANDCA.COM Domain Private Site A'
AddressFamily = 'IPv4'
IPAddress = '192.168.128.10/24'
}
DefaultGatewayAddress IPv4G_2 {
InterfaceAlias = 'LABBUILDER-DCANDDHCPANDCA.COM Domain Private Site A'
AddressFamily = 'IPv4'
Address = '192.168.128.19'
}
DnsServerAddress IPv4D_2 {
InterfaceAlias = 'LABBUILDER-DCANDDHCPANDCA.COM Domain Private Site A'
AddressFamily = 'IPv4'
Address = '192.168.128.10'
}
IPAddress IPv6_2 {
InterfaceAlias = 'LABBUILDER-DCANDDHCPANDCA.COM Domain Private Site A'
AddressFamily = 'IPv6'
IPAddress = 'fd53:ccc5:895a:bc00::a/64'
}
DefaultGatewayAddress IPv6G_2 {
InterfaceAlias = 'LABBUILDER-DCANDDHCPANDCA.COM Domain Private Site A'
AddressFamily = 'IPv6'
Address = 'fd53:ccc5:895a:bc00::13'
}
DnsServerAddress IPv6D_2 {
InterfaceAlias = 'LABBUILDER-DCANDDHCPANDCA.COM Domain Private Site A'
AddressFamily = 'IPv6'
Address = 'fd53:ccc5:895a:bc00::a'
}
}
The only time I ever set DHCPClient is if I want to DHCP to be enabled. But that is just me - there will be lots of different ways people want networking configured.
IMPORTANT: In the next release (7.0.0.0 I expect) of NetworkingDsc the DHCPClient resource will be deprecated and the functionality incorporated into the NetIPInterface resource (see https://github.com/PowerShell/NetworkingDsc/blob/dev/DSCResources/MSFT_NetIPInterface/MSFT_NetIPInterface.schema.mof). This was to simplify and reduce duplication of code and functionality.
For an example of how to set DHCP in the next release: https://github.com/PowerShell/NetworkingDsc/blob/dev/Examples/Resources/IPAddress/2-IPAddress_AddingMultipleStaticIP_Config.ps1#L30