Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to frequently change the DNS server address, and for now I do it by opening 'network and sharing center' - 'local area connection' - properties - ipv4 - and then type the DNS numbers.

Is there a faster way to do it? Can I do it with a batch file or a powershell script? Is there a built in console command to change DNS?

share|improve this question

4 Answers 4

up vote 16 down vote accepted

Primary DNS value:

netsh interface ipv4 set dns "Local Area Connection" static

Secondary value:

netsh interface ipv4 add dns "Local Area Connection" index=2

Which works great IF the name of the connection is correct. If the name isn't "Local Area Connection" then it will not work. If you are running XP you need to change "ipv4" to "ip". IPv6 can be used too.

Set subnet mask, IP Address, and Gateway:

netsh interface ipv4 set address name="Local Area Connection" source=static addr= mask= gateway=

To Find the network connection you can use ipconfig from the cmd line. But you can also use the following for an abbreviated ipconfig result:

ipconfig | find /I "Ethernet adapter"

using the above ipconfig cmd we can loop through the connection and set the dns servers:

:: Set primary and alternate DNS for IPv4 on Windows Server 2000/2003/2008 & Windows XP/Vista/7
SETLOCAL EnableDelayedExpansion

SET adapterName=

FOR /F "tokens=* delims=:" %%a IN ('IPCONFIG ^| FIND /I "ETHERNET ADAPTER"') DO (
SET adapterName=%%a

REM Removes "Ethernet adapter" from the front of the adapter name
SET adapterName=!adapterName:~17!

REM Removes the colon from the end of the adapter name
SET adapterName=!adapterName:~0,-1!

netsh interface ipv4 set dns name="!adapterName!" static primary
netsh interface ipv4 add dns name="!adapterName!" index=2

ipconfig /flushdns

share|improve this answer
Excellent answer. You should include sources for things like Quotes and Code. –  Ƭᴇcʜιᴇ007 Aug 18 '12 at 5:14

There is also a subtle change of syntax between Windows XP and 7 when changing default gateway :

on windows xp :

netsh interface ip set address “Local Area Connection” gateway= gw=0

and on windows 7 :

netsh interface ip set address “Local Area Connection” static

Note that on Windows 7 you must include ip settings and netmask.

Source of information : http://techsultan.com/remotely-change-ip-settings-on-windows-xpvista7-using-netsh/

share|improve this answer

Also to use DNS addresses provided by the DHCP server:

netsh interface ipv4 set dns "Local Area Connection" dhcp
share|improve this answer

Using a Powershell script in Windows 8 or 2012, you may set the values like this:

Set-DnsClientServerAddress -InterfaceAlias Wi-Fi -ServerAddresses "",""

Where wi-Fi is the name of the interface you're interested in. You may list the interfaces by running:


To reset DNS addresses and this use DHCP:

Set-DnsClientServerAddress -InterfaceAlias wi-fi -ResetServerAddresses

Go to this page to see a full description.

Note that the comandlets used here are not available in earlier versions, such as Windows 7.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.