How can I set my DNS settings using the command-prompt or bat file at windows 8
I tried this:
netsh interface ip set dns name="Local Area Connection" source=static addr=none
but not worked.
How can I set my DNS settings using the command-prompt or bat file at windows 8
I tried this:
netsh interface ip set dns name="Local Area Connection" source=static addr=none
but not worked.
First, the network name is likely "Ethernet", not "Local Area Connection". To find out the name you can do this:
netsh interface show interface
Which will show the name under the "Interface Name" column (shown here in bold):
Admin State State Type Interface Name ------------------------------------------------------------------------- Enabled Connected Dedicated Ethernet
Now you can change the primary dns (index=1), assuming that your interface is static (not using dhcp):
netsh interface ipv4 add dnsserver "Ethernet" address=192.168.x.x index=1
2018 Update - The command will work with either dnsserver
(singular) or dnsservers
(plural). The following example uses the latter and is valid as well:
netsh interface ipv4 add dnsservers "Ethernet" address=192.168.x.x index=1
To change DNS to automatic via command, you can run the following command:
netsh interface ip set dns "Local Area Connection" dhcp
Here is another way to change DNS by using WMIC (Windows Management Instrumentation Command-line).
The commands must be run as administrator to apply.
Clear DNS servers:
wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder ()
Set 1 DNS server:
wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder ("8.8.8.8")
Set 2 DNS servers:
wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder ("8.8.8.8", "8.8.4.4")
Set 2 DNS servers on a particular network adapter:
wmic nicconfig where "(IPEnabled=TRUE) and (Description = 'Local Area Connection')" call SetDNSServerSearchOrder ("8.8.8.8", "8.8.4.4")
Another example for setting the domain search list:
wmic nicconfig call SetDNSSuffixSearchOrder ("domain.tld")
There are little difference in command of adding AND changing DNS-IPs:
To Add:
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
netsh interface show interface
To Set/Change: (as OP asked this)
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
Last parameter can be none
:disable DNS, both
:set for primary and secondary DNS both, primary: for primary DNS only. You can notice here we are not using index-parameter as we did in adding DNS.
In the place of static
you can type dhcp
to make DNS setting automatic, but further parameter will not be required.
Note: Tested in windows 8,8.1 & 10.
I wrote this script for switching DNS servers of all currently enabled interfaces to specific address:
@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
None of the answers are working for me on Windows 10, so here's what I use:
@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
This uses Google DNS. You can get interface name with the command netsh int show interface
Batch file for setting a new dns server
@echo off
rem usage: setdns <dnsserver> <interface>
rem default dsnserver is dhcp
rem default interface is Wi-Fi
set dnsserver="%1"
if %dnsserver%=="" set dnsserver="dhcp"
set interface="%2"
if %interface%=="" set interface="Wi-Fi"
echo Showing current DNS setting for interface a%interface%
netsh interface ipv4 show dnsserver %interface%
echo Changing dnsserver on interface %interface% to %dnsserver%
if %dnsserver% == "dhcp" netsh interface ipv4 set dnsserver %interface% %dnsserver%
if NOT %dnsserver% == "dhcp" netsh interface ipv4 add dnsserver %interface% address=%dnsserver% index=1
echo Showing new DNS setting for interface %interface%
netsh interface ipv4 show dnsserver %interface%
Here is your new friend: QuickSetDNS, by NirSoft, amazing as usual.
It also can be used in command line :) with these advantages over netsh:
Just a few caveats:
Now you can change the primary dns (index=1), assuming that your interface is static (not using dhcp)
You can set your DNS servers statically even if you use DHCP to obtain your IP address.
Example under Windows 7 to add two DN servers, the command is as follows:
netsh interface ipv4 add dns "Local Area Connection" address=192.168.x.x index=1
netsh interface ipv4 add dns "Local Area Connection" address=192.168.x.x index=2