Using netsh to set multiple DNS server addresses in Windows

This content is 19 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

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!

30 thoughts on “Using netsh to set multiple DNS server addresses in Windows

  1. 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. 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.

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. For simplified chinese PCs, the correct command is usually:

    set dns “本地连接” static 192.168.60.2

    (本地连接 = Local Area Connection)

  9. 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

  10. 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 :)

  11. 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

  12. 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

  13. 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.

  14. Yep. One bit of effort on your part to create the blog has helped an awful lot of people over a long time. Thanks

  15. To get this to work across all systems (w2k8, w2k3, r2 and x64) I had to run my netsh command like the following (we rename our adapters Primary-VLANXXX and Backup):

    Hint: I used psexec to push this out in a batch file and run it with system privleges

    netsh interface ip delete dns name=”Primary” addr=all (Purges existing DNS)
    netsh interface ip add dns name=”Primary” 10.x.x.1 index=1 (Adds Primary DNS)
    netsh interface ip add dns name=”Primary” 10.x.x.2 index=2 (Adds Secondard DNS)
    ipconfig /flushdns (flush local DNS cache)
    ipconfig /registerdns (register ip on new DNS)
    nbtstat -RR (refresh netbios)

  16. Great stuff here that’s helped a lot.

    One thing we don’t have is a standard name for the network interface that we need to update. Is there any way to have this apply without having to specifically define the network interface? I guess this means, is there a way to identify all interfaces that are configured with existing settings and update them? At the moment, the manualy process is to run “netsh interface ip show interfaces” and then update the script below:

    netsh interface ip set dns “Local Area Connection” static 10.0.0.1
    netsh interface ip add dns “Local Area Connection” 10.0.0.2 index=2
    netsh interface ip set wins “Local Area Connection” static 10.0.0.1
    netsh interface ip add wins “Local Area Connection” 10.0.0.2 index=2
    ipconfig /flushdns
    ipconfig /registerdns
    nbtstat -RR

    Any thoughts?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.