本文调用 CMD 命令来修复 DNS 查找问题。除最后两个命令外,所有命令均成功:
netsh int ip set dns
netsh winsock reset
当我尝试第一个命令时,CMD 要求输入参数。我无法理解 CMD 的正确语法提示,所以我谷歌了一下。找到的最好的答案是这其中包括如下冗长的命令:
netsh interface ip set dns name="Local Area Connection" source=static addr=none
netsh interface ip add dns name="Local Area Connection" addr=8.8.4.4 index=1
netsh interface ip add dns name="Local Area Connection" addr=8.8.8.8 index=2
netsh interface ip set dns name="Local Area Connection" source=dhcp
我不知道这些参数是否是为解决我的问题而设计的,所以我不敢运行它们。Microsoft 文档未提及我需要的命令(只有 netsh IPsec,没有 netsh IP)
我想成功执行前两个命令,但我不知道要包含哪些参数。
答案1
Windows 命令“netsh int ip set dns”需要哪些参数?
您可以使用netsh int ipv4 set dns help
命令行语法来获取帮助在您尝试运行的命令上,并解释要传递给它的适用参数。
在您的特定实例中,您可以传递name
要在其上设置 DNS 的接口名称的参数及其值,以及addr
将用于 DNS 的 DNS 服务器的 IP 地址的参数及其值。
C:\Users\User>netsh int ipv4 set dns help
Usage: set dnsservers [name=]<string> [source=]dhcp|static
[[address=]<IP address>|none]
[[register=]none|primary|both]
[[validate=]yes|no]
Parameters:
Tag Value
name - The name or index of the interface.
source - One of the following values:
dhcp: Sets DHCP as the source for configuring DNS
servers for the specific interface.
static: Sets the source for configuring DNS servers
to local static configuration.
address - One of the following values:
<IP address>: An IP address for a DNS server.
none: Clears the list of DNS servers.
register - One of the following values:
none: Disables Dynamic DNS registration.
primary: Register under the primary DNS suffix only.
both: Register under both the primary DNS suffix, as
well as under the connection-specific suffix.
validate - Specifies whether validation of the DNS server setting
will be performed. The value is yes by default.
Remarks: Sets DNS server configuration to either DHCP or static mode. Only
when source is 'static', is the 'addr' option also available for
configuring a static list of DNS server IP addresses for the
specified interface. If Validate switch is yes, then
the newly set DNS server is validated.
Examples:
set dnsservers name="Wired Ethernet Connection" source=dhcp
set dnsservers "Wired Ethernet Connection" static 10.0.0.1 primary
答案2
为了跟进 JUICED_IT 的回答,网络名称可能是“以太网”,而不是“本地连接”。要找出名称,您可以执行以下操作:
netsh interface show interface
这将在“接口名称”列下显示名称(此处以粗体显示):
管理状态 状态类型 接口名称 ------------------------------------------------------------------------- 已启用 已连接 专用 以太网
现在您可以更改主 DNS(索引 = 1),假设您的接口是静态的(不使用 dhcp):
netsh interface ipv4 add dnsserver "Ethernet" address=192.168.x.x index=1
netsh winsock reset
,正如命令所述,将 winsock 目录重置为干净的状态。
c:\>netsh winsock reset /?
Resets Winsock Catalog to a clean state. All Winsock Layered Service Providers which were previously installed must be reinstalled. This command does not affect Winsock Name Space Provider entries.