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 (8.8.8.8 and 8.8.4.4)
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 OFF 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 PAUSE ECHO Setting primary DNS server... netsh interface i set dns "WiFi" static 8.8.8.8 ECHO ...done. Setting secondary DNS server... netsh interface ip add dns name="WiFi" addr=8.8.4.4 index=2 ECHO ...done. PAUSE
NOTE: My wireless connection name is “WiFi”. Adjust it to match yours accordingly.
Posted on August 21, 2012, in PC stuff and tagged 7, dns, dns server, dns settings, netsh, windows, windows7. Bookmark the permalink. 9 Comments.
nice script. which tag is used un wordpress to publish batchscript code?
Hey, thanks for your comment. I am using just the tag, but it does not seem to do any highlighting on batch scripts.
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
Thanks;)
Thanks. I got the first dns server to populate, but not the second until now.
You are my inhalation, I have few web logs and rarely run out from post bdeeaddddegg
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
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!
Good post. I absolutely appreciate this site. Continue the good work!