Blog Archives

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.

CMD output

Advertisements