使用PowerShell将IPv6 DNS地址设置为本地主机

时间:2014-07-29 18:41:35

标签: powershell dns ipv6

我在Windows 8.1上运行本地DNS服务器,并且想要创建PowerShell脚本以自动在此DNS服务器和DHCP提供的服务器之间切换。

我想出了

Set-DnsClientServerAddress -InterfaceIndex 3 -ServerAddresses 127.0.0.1 -Validate

可用于设置本地主机的DNS地址,以及

Set-DnsClientServerAddress -InterfaceIndex 3 -ResetServerAddresses

将值重置为DHCP值。

我还想将DNS服务器的IPv6地址更改为本地主机(:: 1),但是当我尝试使用

执行此操作时
Set-DnsClientServerAddress -InterfaceIndex 3 -ServerAddresses "::1" -Validate

我得到以下'一般错误',我无法追溯到它的原因:

Set-DnsClientServerAddress : A general error occurred that is not covered by a more specific error code.
At line:1 char:1
+ Set-DnsClientServerAddress -InterfaceIndex 3 -Validate -ServerAddresses "::1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (MSFT_DNSClientS...stemName = "2"):ROOT/StandardCi...ntServerAddress) [Set
   -DnsClientServerAddress], CimException
    + FullyQualifiedErrorId : MI RESULT 1,Set-DnsClientServerAddress

Set-DnsClientServerAddress : A general error occurred that is not covered by a more specific error code.
At line:1 char:1
+ Set-DnsClientServerAddress -InterfaceIndex 3 -Validate -ServerAddresses "::1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_DNSClientS...temName = "23"):ROOT/StandardCi...ntServerAddress) [Set
   -DnsClientServerAddress], CimException
    + FullyQualifiedErrorId : MI RESULT 1,Set-DnsClientServerAddress

必须使用哪个命令将IPv6 DNS地址设置为本地主机,为什么我当前的解决方案会产生错误?

1 个答案:

答案 0 :(得分:0)

-Validate这意味着实际尝试连接到指定的DNS服务器。如果他们没有回复,则会发生此错误。

当然,如果您确实打算使用它, 应该在指定地址上运行DNS服务器......