Skip to content

Instantly share code, notes, and snippets.

@valmayaki
Forked from n074v41l4bl34u/set-dns.cmd
Created June 20, 2016 18:05
Show Gist options
  • Save valmayaki/1fce75afec6bcbbdbc53e109e9ea270d to your computer and use it in GitHub Desktop.
Save valmayaki/1fce75afec6bcbbdbc53e109e9ea270d to your computer and use it in GitHub Desktop.
set static dns for network connection using windows console cmd script
@echo off
IF [%1] EQU [] goto noInterface
:: OPENDNS - OpenDNS, LLC,US
set DNS1=208.67.222.123
:: Google DNS
set DNS2=8.8.4.4
for /f "skip=2 tokens=1,2,3*" %%i in ('netsh int show interface') do (
if %%i equ Enabled if %%j equ Connected if "%%l" equ %1 (
echo Changing "%%l" : %DNS1% + %DNS2%
netsh int ipv4 set dns name="%%l" static %DNS1% primary validate=no
netsh int ipv4 add dns name="%%l" %DNS2% index=2 validate=no
)
)
ipconfig /flushdns
goto exit
:noInterface
echo syntax: set-dns.cmd interface_name_in_quotes
echo example: set-dns.cmd "Local Area Connection"
:exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment