Skip to content

Instantly share code, notes, and snippets.

@itsimba
Created March 28, 2020 12:25
Show Gist options
  • Save itsimba/74941ba9d3beceadd2cd3764faaa448f to your computer and use it in GitHub Desktop.
Save itsimba/74941ba9d3beceadd2cd3764faaa448f to your computer and use it in GitHub Desktop.
:: Set primary and alternate DNS for IPv4 on Windows Server 2000/2003/2008 &
:: Windows XP/Vista/7
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET adapterName=
FOR /F "tokens=* delims=:" %%a IN ('IPCONFIG ^| FIND /I "ETHERNET ADAPTER"') DO (
SET adapterName=%%a
REM Removes "Ethernet adapter" from the front of the adapter name
SET adapterName=!adapterName:~17!
REM Removes the colon from the end of the adapter name
SET adapterName=!adapterName:~0,-1!
netsh interface ipv4 set dns name="!adapterName!" static 114.114.114.114 primary
netsh interface ipv4 add dns name="!adapterName!" 119.29.29.29 index=2
)
ipconfig /flushdns
:EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment