Main menu

SmartFeed by FeedBurner Subscribe to the site feed.


If you find the information here useful, then please consider a small donation, or linking to this site.

Recent Contributions

Calendar

October 2005
M T W T F S S
« Sep   Nov »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Archive

Using netsh to set multiple DNS server addresses in Windows

During my recent two days of torment caused by a flaky Java application, I had to change the preferred and alternate DNS server entries for one of my network cards. Ordinarily that would be simple, but with an unresponsive Explorer interface refusing to open any network connection dialogs I needed to do it from the command line.

Enter the network shell (netsh) - a fantastic command line utility that has sneaked into recent versions of Windows and seems to have more and more functionality added with each new release.

After entering the netsh shell, interface ip got me to the TCP/IP interface settings; then show dns gave me the details of the current DNS servers; set dns "Local Area Connection" ipaddress allowed me to set the preferred DNS server and add dns "Local Area Connection" ipaddress index=2 set the alternate DNS server (that was the difficult one to work out - I had tried to set dns with a list of IP addresses but that does not work!); finally, exit the network shell and type ipconfig -all to check settings the normal way.

I love the command prompt!

Comments

1

Comment from chuck
Time: Monday 24 October 2005, 18:42

Mark,

Thanks for the post - it was definitely helpful for me :)

I found your blog by typing “netsh multiple dns” in good old google and yours popped up as the top entry and had the information I needed. Thanks again!

Chuck

2

Comment from Mark
Time: Monday 24 October 2005, 23:51

Chuck, Glad to hear you found this useful! You can also find something similar in one of the comments on the Windows IT Pro article “cool things to do with netsh“.

3

Comment from Lester
Time: Tuesday 15 November 2005, 17:43

I was looking on the internet on how to add secondary DNS. I didn’t find this info on Microsoft’s site. I’m sure its there somewhere. Anyways, I found your website and was successful. Thanks for posting it.

4

Comment from Gregory Fenton
Time: Saturday 14 January 2006, 20:00

Thanks a lot, I have a network card that does not appear in “Network Connections”.. the info here allowed me to add a custom DNS server for opennic (http://www.opennic.unrated.net or the much cooler http://www.opennic.glue) using the command

netsh add dns 83.217.93.246 index=2

I’d suggest you try it - there’s a whole new world out there - never mind .com, how about your own website ending in .indy, .geek, .parody and many many more.. http://www.opennic.unrated.net/tlds.html

It may sound like an advert, but it’s not.. check them out :)

And thsnks again for the netsh help

5

Comment from Anonymous
Time: Monday 3 April 2006, 10:59

Hello,

the only way it worked on my Windows XP prof. was to set alternate dns server first and then to add primary server with index=1 :

netsh interface ip set dns “Local Area Connection” static (secondaryserveraddress)

netsh interface ip add dns “Local Area Connection” (primaryserveraddress) index=1

loobrush

6

Comment from Anonymous
Time: Saturday 17 June 2006, 1:21

On Windows XP to set a primary and static DNS server use…

netsh interface ip set dns local static xxx.xxx.xxx.xxx
netsh interface ip add dns local xxx.xxx.xxx.xxx

7

Comment from Sanjay M
Time: Thursday 21 December 2006, 6:17

I alternate between DNS and static IP between my home and office, and this entry was really cool, thanks a lot Mark! I’d written 2 batch files which did this, but didn’t know about the index=2 part for alternate dns and found it here.

Just for completion, here’s how to set up dhcp:

netsh interface ip set dns “Local Area Connection” dhcp

8

Comment from Anonymous
Time: Tuesday 20 February 2007, 13:37

Never managed to get this working, so not sure if the functionality has been removed by an update or something, but the best way to add additional DNS (or WINS) addresses is to first set your primary address:

netsh interface ip set dns name=”Local Area Connection” static IPADDRESS

then for every additional DNS server:

netsh interface ip add dns name=”Local Area Connection” IPADDRESS

9

Comment from Anonymous
Time: Monday 26 February 2007, 11:32

For simplified chinese PCs, the correct command is usually:

set dns “本地连接” static 192.168.60.2

(本地连接 = Local Area Connection)

10

Comment from Arty
Time: Wednesday 14 March 2007, 8:24

Awesome. Exactly what I was trying to do. You have saved me a lot of hassle.

Thanks!

11

Comment from mak
Time: Tuesday 3 July 2007, 9:35

thanks a million helped me out now i don hav to manually change my setting
I wrote batch files to make it simpler
Thanks again

12

Pingback from Mark’s (we)Blog » A few commands to get started with Windows Server Core
Time: Tuesday 14 August 2007, 19:11

[…] Other links that may be useful include the Windows command line reference and my own post on using netsh to set multiple DNS server addresses. […]

13

Comment from cw1972
Time: Tuesday 25 September 2007, 9:27

Thank you for this, the index=2 was just what I needed, the help netsh gives does not make it obvious that this is for secondary dns.

I too found your blog by typing “add secondary dns using netsh” into google.

Many thanks :)

14

Comment from Deb
Time: Wednesday 31 October 2007, 12:52

for Alternate DNS we need to mention
netsh add dns 83.217.93.246 index=2
This really works.

15

Comment from Anonymous
Time: Monday 3 March 2008, 9:58

Thnank you very much for sharing this info..

16

Comment from Larry Gurley
Time: Friday 11 April 2008, 21:24

After running netsh interface dump I looked for the line that began with set dns and add dns and prepended netsh interface ip. Looked like this. I’m sure this will wrap but it was two commands.

netsh interface ip set dns name=”Local Area Connection” source=static addr=10.69.1.50 register=PRIMARY

netsh interface ip add dns name=”Local Area Connection” addr=10.69.1.51 index=2

17

Comment from Sergey Jamharyam
Time: Wednesday 7 May 2008, 8:51

I tried to set 3 dns with netsh, how can help me? When I put 3 dns settings no one couldn’t set.
I’ll put answer on http://www.infoexpanse.com for other finders as me:)

18

Comment from Axxel
Time: Thursday 29 May 2008, 11:12

Many THX!!! Unbelivable that the online-help don’t mention this :-(

19

Comment from Anders Olsson
Time: Monday 9 June 2008, 14:59

Thanks for sharing, man!

20

Comment from boulder
Time: Friday 22 August 2008, 20:16

In windows 2003 Sp2 the working command lines are:
netsh interface ip set dns name=”sat” source=static 10.0.0.1
netsh interface ip add dns name=”sat” 10.0.0.2
netsh interface ip add dns name=”sat” 10.0.0.3

21

Comment from Overcast
Time: Saturday 13 December 2008, 19:06

Like wise :) Same Search - index=2. It cut many minutes off a time-critical server migration. Thanks!

Google search for “netsh int ip set dns secondary” did it.

22

Comment from aaa
Time: Tuesday 10 March 2009, 7:38

thanks a lot for this tip

Write a comment

Please note the rules for comments and the privacy policy and data protection notice. I'm sorry but, because not everyone sticks to the rules, I've had to implement some spam prevention measures - if you're experiencing difficulties leaving a comment, please let me know.





The following XHTML tags may be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>