Setting DNS servers using NETSH

I have just faced an interesting problem at work. When I log onto work’s WiFi network I have to use a DNS server that is assigned by DHCP. After logging in, there is some bug that does not allow me access to company’s web page that is public on the Internet. So I came up with this little trick:

  • Set DNS to be retrieved via DHCP
  • Log into the network
  • Set DNS back to Google ones ( and

And all of this can easily be done using NETSH command (everything is in a “.bat” file. It requires to be run with administrator priviliges):


ECHO Setting DNS to DHCP mode...
netsh interface ip set dns name="WiFi" DHCP
ECHO ...done. Press ENTER to set DNS back to Google's servers


ECHO Setting primary DNS server...
netsh interface i set dns "WiFi" static
ECHO ...done. Setting secondary DNS server...
netsh interface ip add dns name="WiFi" addr= index=2

ECHO ...done.


NOTE: My wireless connection name is “WiFi”. Adjust it to match yours accordingly.

CMD output


About Vaidas Sirtautas

Posted on August 21, 2012, in PC stuff and tagged , , , , , , . Bookmark the permalink. 9 Comments.

  1. nice script. which tag is used un wordpress to publish batchscript code?

  2. Ur post, “Setting DNS servers using NETSH Vaidas Sirtautas’ Blog” was indeed truly worth writing a comment on! Really desired to say you actually did a wonderful job. Thanks for your effort ,Felipa

  3. Thanks. I got the first dns server to populate, but not the second until now.

  4. You are my inhalation, I have few web logs and rarely run out from post bdeeaddddegg

  5. I was looking through some of your blog posts on this internet site and I conceive this web site is rattling informative ! Keep on posting . fkeedbacddad

  6. you are truly a good webmaster. The site loading speed is amazing.
    It kind of feels that you are doing any distinctive trick.
    In addition, The contents are masterwork. you have performed a excellent job on this subject!

  7. Good post. I absolutely appreciate this site. Continue the good work!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: