How can I set / change DNS using the command-prompt at windows 8

Windows 8DnsCommand Prompt

Windows 8 Problem Overview


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.

Windows 8 Solutions


Solution 1 - Windows 8

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

Solution 2 - Windows 8

To change DNS to automatic via command, you can run the following command:

netsh interface ip set dns "Local Area Connection" dhcp

Solution 3 - Windows 8

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")

Solution 4 - Windows 8

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
  • Here, to know "Network Interface Name", type command netsh interface show interface
  • 8.8.8.8 is Google's recursive DNS server, use it, if your's not working

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.

Solution 5 - Windows 8

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

Solution 6 - Windows 8

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

Solution 7 - Windows 8

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%

Solution 8 - Windows 8

Here is your new friend: QuickSetDNS, by NirSoft, amazing as usual.

screenshot

It also can be used in command line :) with these advantages over netsh:

  • easier syntax, in particular for setting the alternate server
  • automatically asks for privilege elevation


Just a few caveats:

  • supports only setting of IPv4, not of IPv6
    • since QuickSetDNS 1.30, setting IPv6 DNS servers is also supported ;)
  • in command line, the adapter UUID should be used, not the friendly name (e.g. "Local Area Connection")
    • since QuickSetDNS 1.21, connection names are also supported ;)

Solution 9 - Windows 8

> 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZuhair TahaView Question on Stackoverflow
Solution 1 - Windows 8chue xView Answer on Stackoverflow
Solution 2 - Windows 8Marcos CassianoView Answer on Stackoverflow
Solution 3 - Windows 8XP1View Answer on Stackoverflow
Solution 4 - Windows 8Adarsh RajputView Answer on Stackoverflow
Solution 5 - Windows 8MeowView Answer on Stackoverflow
Solution 6 - Windows 8MrVaykadjiView Answer on Stackoverflow
Solution 7 - Windows 8BSalitaView Answer on Stackoverflow
Solution 8 - Windows 8Gras DoubleView Answer on Stackoverflow
Solution 9 - Windows 8ZathraszeroView Answer on Stackoverflow