如何应用 xNetworking xIPAddress 所需状态配置 (DSC)?

如何应用 xNetworking xIPAddress 所需状态配置 (DSC)?

使用 Windows Server 2012 R2。

目标是设置服务器的 IPv4 地址。正如 DSC 在下面详细消息中正确指出的那样,预期的 [ip 是] 192.168.0.203,[而] 实际的 [ip 是] 192.168.0.205

以下错误信息:

Start-DscConfiguration -Path .\BasicServer -Verbose -Wait -Force

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' =
MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer ComputerName with user sid S-1-5-21-139086020-2308268882-217435134-1104.
VERBOSE: [ComputerName]: LCM:  [ Start  Set      ]
VERBOSE: [ComputerName]: LCM:  [ Start  Resource ]  [[xIPAddress]IPAddress]
VERBOSE: [ComputerName]: LCM:  [ Start  Test     ]  [[xIPAddress]IPAddress]
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] Checking the IPAddress ...
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] IPAddress not correct. Expected 192.168.0.203, actual 192.168.0.205
VERBOSE: [ComputerName]: LCM:  [ End    Test     ]  [[xIPAddress]IPAddress]  in 0.0310 seconds.
VERBOSE: [ComputerName]: LCM:  [ Start  Set      ]  [[xIPAddress]IPAddress]
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] Checking the IPAddress ...
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] IPAddress not correct. Expected 192.168.0.203, actual 192.168.0.205
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] Setting IPAddress ...
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] Instance DefaultGateway already exists
VERBOSE: [ComputerName]: LCM:  [ End    Set      ]  [[xIPAddress]IPAddress]  in 0.0620 seconds.
PowerShell DSC resource MSFT_xIPAddress  failed to execute Set-TargetResource functionality with error message: Can not set or find valid IPAddress using
InterfaceAlias Ethernet and AddressFamily IPv4
+ CategoryInfo          : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName        : ComputerName.domain.com

The SendConfigurationApply function did not succeed.
+ CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName        : ComputerName.domain.com

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.268 seconds

... 应用以下 xNetworking DSC 配置时抛出:

Import-DscResource -Module xNetworking

Node $NodeFQDN {
xIPAddress IPAddress {
    InterfaceAlias = "Ethernet"
    IPAddress = $IPv4
    AddressFamily = "IPV4"
    DefaultGateway = '192.168.0.1'
    SubnetMask = 24
}}

其中 $IPv4 = '192.168.0.203'。

我注意到本地配置管理器能够进行 Test-DSCConfiguration,但无法应用任何与 IP 相关的更改。我已通过在 IP 已正确设置的情况下在系统上运行上述配置对此进行了测试。

消息“无法使用 InterfaceAlias Ethernet 和 AddressFamily IPv4 设置或找到有效的 IPAddress”令人困惑,因为 LCM 显然能够在 Test-DSCConfiguration 操作期间找到适配器。

本地配置管理器无法应用配置的原因是什么?我没看到什么?

答案1

解决方案是从配置中删除默认网关:DefaultGateway = '192.168.0.1'

看起来,如果除了基本配置(IPAddress、InterfaceAlias、SubnetMask、AddressFamily)之外还有任何配置,DSC 将重点关注附加项目,并将基本配置视为参考。考虑以下内容:

xIPAddress IPAddress {
    InterfaceAlias = 'Ethernet'
    IPAddress = '192.168.0.203'
    AddressFamily = 'IPV4'
    SubnetMask = 24
}

上述配置将设置IP地址为192.168.0.203。

 xIPAddress IPAddress {
    InterfaceAlias = 'Ethernet'
    IPAddress = '192.168.0.203'
    AddressFamily = 'IPV4'
    SubnetMask = 24
    DefaultGateway = '192.168.0.1'
}

上述配置将找到一个名为“以太网”的适配器,其 IP 地址为 192.168.0.203,并将其默认网关配置为 192.168.0.1。在我的问题中,本地配置管理器无法找到这样的适配器。我试图同时设置 IP 和网关。

这一发现让我明白,设置 IP 和配置其他适配器属性不能在单个配置中完成。这在某种程度上消除了使用单个(是的,只有 1 个)脚本端到端配置服务器的想法。

我说的对吗?

附言:我也遇到过配置附加新 IP 而不是替换的情况。现在不讨论这个,但这种行为非常有趣……

相关内容