Main menu


Advertisements

Originally created as a place for me to store some notes, this blog comments on my daily encounters with technology and aims to share some of this knowledge with fellow systems administrators and technical architects across the 'net. Amazingly, it's become quite popular!

SmartFeed by FeedBurner Subscribe to the site feed.

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

Recent Contributions

Tag cloud

Active Directory Adobe ADSL Apache Apple BizTalk Server Blogger Blogging Bluetooth CA Certification Configuration Manager (SMS) Dell Desktop Search Digital photography DNS Domain names DRM Dynamics CRM E-mail Exchange Hosted Services Exchange Server File formats Flash Forefront Friends Front Row FTP Google Green computing Groove History Host Integration Server HP Humour IAG IBM/Lenovo IIS iLife Industry trends Instant messaging Internet iPhone iPod ISA Server iSight IT law IT Operations iTunes Java Linux Live Meeting Live/Office Communications Server Macintosh Mainframes Malware Microsoft Microsoft.NET MIIS Mobility Money Motoring MS-DOS NetWare Networking hardware Networks Novell Office OpenOffice Operations Manager OS deployment OS X Outlook P2P Parallels Desktop Patch management PC hardware Photography Photoshop Podcasts PowerPoint Press coverage Professional skills Project Proxy Server QOS QuickTime Real Player Remote access RFID RSS SAP Scripting Search Security Server hardware SharePoint Site notices Social networking SoftGrid Software licensing Solaris Spam SQL Server Storage Symantec System Center Tablet PCs TCP/IP Telephony TV Useful books Useful software Useful websites Virtual Infrastructure Virtual PC Virtual Server/Hyper-V Virtualisation Visio Visual Studio VMM VMware VMware Fusion VMware Player VMware Server VMware Workstation Waffle and randomness Web browsers Web services Website development Wi-Fi Windows Windows 2000 Windows 7 Windows 9x Windows Home Server Windows Live/MSN Windows Media Windows Mobile Windows NT Windows PE Windows Server 2003 Windows Server 2008 Windows Small Business Server 2003 Windows Vista Windows XP Word WordPerfect WordPress WWW XBox 360 Xen Zune

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!

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>