Skip to content

Instantly share code, notes, and snippets.

@n074v41l4bl34u
Created March 20, 2016 19:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save n074v41l4bl34u/e237c0f199b2bb68bf1c to your computer and use it in GitHub Desktop.
Save n074v41l4bl34u/e237c0f199b2bb68bf1c 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