Created
March 20, 2016 19:41
-
-
Save n074v41l4bl34u/e237c0f199b2bb68bf1c to your computer and use it in GitHub Desktop.
set static dns for network connection using windows console cmd script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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