Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to switch Internet Protocol Version 4 (TCP/IPv4) and Internet Protocol Version 6 (TCP/IPv6) settings for DNS server configuration from "Obtain DNS server address automatically" to hard coded values (for Google's DNS servers) and back. It's kind of a hassle to do manually (I need to go to Control Panel-Network and Internet-Network Connections, open Wireless Network Connection 2, then open Properties for the corresponding version, enter the DNS server values, and repeat for the other one). Is there a utility or script that would automate the process? Thanks.

share|improve this question
Can't you just have the DHCP server change them as needed? – Shane Madden Apr 18 '12 at 5:31
Not sure what you mean, Shane. I'm trying to implement a workaround for AT&T router/DNS issue on the client side (here is background: – Alek Davis Apr 18 '12 at 5:46
Do you really need to do this for IPv6? If so, why? – joeqwerty Apr 18 '12 at 10:32
I'm not sure if I really need to. It was in the instructions for the workaround (for the router issue) I saw somewhere, but it may work with just changing IPv4. Would be nice to be able to take care of IPv6 just in case. – Alek Davis Apr 18 '12 at 14:26
up vote 2 down vote accepted

From elevated command prompt (or from .bat file):

netsh interface ipv4 set dnsserver "Wireless Network Connection 2" source=static addr=
netsh interface ipv4 add dnsserver "Wireless Network Connection 2" addr= index=2


netsh interface ipv4 set dnsserver "Wireless Network Connection 2" source=dhcp

You can just replace ipv4 with ipv6 (and proper address of course).

share|improve this answer
Great, thanks. Only for some reason the second command (the one that sets DNS server to causes error: "'source' is not a valid argument for this command. The syntax supplied for this command is not valid. Check help for the correct syntax." – Alek Davis Apr 20 '12 at 4:24
ah, yes, source=static is not needed when adding the second nameserver. I have edited the answer – Dusan Bajic Apr 20 '12 at 7:41

In powershell:

$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'" 
$DNSServers = "",""  

To revert:


(no parameters=null, this will put it back in automatic mode)


share|improve this answer
Thanks Lucas. I assume this is for IPv4. How do you get the WMI object for IPv6? Also, how do you switch it back to "Obtain DNS server address automatically"? – Alek Davis Apr 18 '12 at 5:42
I can't seem to find how to do it in powershell with IPv6. To obtain a DNS address automatically you would need to do a new DHCP request, there isn't a way (I'm aware off) to just got the DNS server from a DHCP server. – Lucas Kauffman Apr 18 '12 at 6:05
That's okay. What about going back it back to "Obtain DNS server address automatically"? – Alek Davis Apr 18 '12 at 14:27
I'll add it to the answer – Lucas Kauffman Apr 18 '12 at 18:08
Great, thanks. I'll mark is as the accepted answer, but if anyone has an idea hot to handle IPv6 or can offer other alternatives (e.g. do the same without PowerShell, please post it). – Alek Davis Apr 18 '12 at 21:39

Some manufacturers (IBM/Lenovo, Sony to mention just a few) used to supply users with their own (branded) utilities to solve that. It mostly used on notebook PCs: when you notebook connected to 'known' network, the utility automatically set up whatever you need to live in that network (proxy, DNS, maybe secondary IPs on the same interfaces). If you're using that kind of system, try to use that option.

On the other hand, why don't you set that up on DCHP servers in that networks? Static (by MAC) settings are something not hard to implement, anyway.

share|improve this answer
Because I do not own the corporate network. – Alek Davis May 4 '12 at 16:36
No need to own the network to have some talk with 'network' guys so they create some settings for you (if it won't be against your corporate rules) :) Ok, here is the utilities for you to consider: Free IP Switcher or Net Profiles. – Alexander May 4 '12 at 20:48
Having some talk with 'network' guys? Ha-ha-ha... Very funny. Thanks for the links to the apps. They look like what I may have needed in the first place (would be better than a script option). Appreciate it. – Alek Davis May 5 '12 at 0:01
Okay, tried both and uninstalled. Net Profiles does not seem to do anything. Launched is normally and as an admin: nothing happens. IP Switcher looks a lot more messy than the script-based solution. Btw, when will people learn to build installers that automatically run as administrators. It's 2012 for crying out loud. – Alek Davis May 5 '12 at 5:32
Sorry to hear that, once one of it (Net Profiles) has helped me very nice, but that was on XP (and it was long ago and maybe different SP version). Look at NetSetMan, looks promising (and claims to be freeware for non-commercial purposes)... – Alexander May 5 '12 at 5:55

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.