Zuh*_*aha 74 dns command-prompt windows-8
如何在Windows 8中使用命令提示符或bat文件设置DNS设置
我试过这个:
netsh interface ip set dns name="Local Area Connection" source=static addr=none
Run Code Online (Sandbox Code Playgroud)
但没有奏效.
chu*_*e x 84
首先,网络名称可能是"以太网",而不是"本地连接".要查找名称,您可以执行以下操作:
netsh interface show interface
Run Code Online (Sandbox Code Playgroud)
这将在"接口名称"列下显示名称(以粗体显示):
Admin State State Type Interface Name ------------------------------------------------------------------------- Enabled Connected Dedicated Ethernet
现在您可以更改主dns(index = 1),假设您的接口是静态的(不使用dhcp):
netsh interface ipv4 add dnsserver "Ethernet" address=192.168.x.x index=1
Run Code Online (Sandbox Code Playgroud)
2018更新 - 该命令将与dnsserver(单数)或dnsservers(复数)一起使用.以下示例使用后者并且也是有效的:
netsh interface ipv4 add dnsservers "Ethernet" address=192.168.x.x index=1
小智 27
要通过命令将DNS更改为自动,可以运行以下命令:
netsh interface ip set dns "Local Area Connection" dhcp
Run Code Online (Sandbox Code Playgroud)
Ada*_*put 19
添加和更改 DNS-IP的命令几乎没有区别:
加上:
Syntax:
netsh interface ipv4 add dnsserver "Network Interface Name" dns.server.ip index=1(for primary)2(for secondary)
Eg:
netsh interface ipv4 add dnsserver "Ethernet" 8.8.8.8 index=1
Run Code Online (Sandbox Code Playgroud)
netsh interface show interface设置/更改:(因为OP问这个)
Syntax:
netsh interface ipv4 set dnsservers "Network Interface Name" static dns.server.ip primary
Eg:
netsh interface ipv4 set dnsservers "Wi-Fi" static 8.8.4.4 primary
netsh interface ipv4 set dnsservers "Wi-Fi" dhcp
Run Code Online (Sandbox Code Playgroud)
最后一个参数可以是none:禁用DNS,:both为主DNS和辅助DNS设置,主要:仅用于主DNS.你可以注意到我们没有像添加DNS那样使用index-parameter.
在这个地方static,你可以输入dhcp进行DNS设置自动的,但进一步的参数将不再需要.
注意:在Windows 8,8.1和10中测试过.
XP1*_*XP1 18
以下是使用WMIC(Windows Management Instrumentation命令行)更改DNS的另一种方法.
必须以管理员身份运行命令才能应用.
清除DNS服务器:
wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder ()
Run Code Online (Sandbox Code Playgroud)
设置1个DNS服务器:
wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder ("8.8.8.8")
Run Code Online (Sandbox Code Playgroud)
设置2个DNS服务器:
wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder ("8.8.8.8", "8.8.4.4")
Run Code Online (Sandbox Code Playgroud)
在特定网络适配器上设置2个DNS服务器:
wmic nicconfig where "(IPEnabled=TRUE) and (Description = 'Local Area Connection')" call SetDNSServerSearchOrder ("8.8.8.8", "8.8.4.4")
Run Code Online (Sandbox Code Playgroud)
设置域搜索列表的另一个示例:
wmic nicconfig call SetDNSSuffixSearchOrder ("domain.tld")
Run Code Online (Sandbox Code Playgroud)
Meo*_*eow 15
我写了这个脚本,用于将所有当前启用的接口的DNS服务器切换到特定地址:
@echo off
:: Google DNS
set DNS1=8.8.8.8
set DNS2=8.8.4.4
for /f "tokens=1,2,3*" %%i in ('netsh int show interface') do (
if %%i equ Enabled (
echo Changing "%%l" : %DNS1% + %DNS2%
netsh int ipv4 set dns name="%%l" static %DNS1% primary validate=no
netsh int ipv4 add dns name="%%l" %DNS2% index=2 validate=no
)
)
ipconfig /flushdns
:EOF
Run Code Online (Sandbox Code Playgroud)
MrV*_*dji 10
在Windows 10上没有任何答案适合我,所以这是我使用的:
@echo off
set DNS1=8.8.8.8
set DNS2=8.8.4.4
set INTERFACE=Ethernet
netsh int ipv4 set dns name="%INTERFACE%" static %DNS1% primary validate=no
netsh int ipv4 add dns name="%INTERFACE%" %DNS2% index=2
ipconfig /flushdns
pause
Run Code Online (Sandbox Code Playgroud)
这使用Google DNS.您可以使用该命令获取接口名称netsh int show interface