Friday, October 7, 2016

[SCRIPTHACKS] How to quickly change DNS with Windows batch script.

There is probably a few reasons you might want to change DNS on your PC from time to time. For me, I use it to circumvent, region blocking on streaming services. However to change the DNS manually every time manually is tedious. SO I wrote a simple batch script to help me change the DNS in just 2 clicks away.

Step 1 : Save the script below

Save the script below into a *.bat file. i.e. changeDNS.bat. The option below is for switching between DHCP and Google's Public DNS. However you modify the scripts and add more options as you like. 

The script should work on windows 8 and above. Probably works on older windows also. Somebody need to check it out.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@echo off

echo Choose Option
echo --------------
echo 1. DHCP DNS
echo 2. GOOGLE DNS
set /p opt="Option : "

set INTERFACE=Wi-Fi

if %opt%==1 goto dhcp
if %opt%==2 goto google

goto end

:dhcp
echo setting dhcp
netsh interface ip set dns "%INTERFACE%" dhcp
goto end

:google
set DNS1=8.8.8.8
set DNS2=8.8.4.4

netsh int ipv4 set dns name="%INTERFACE%" static %DNS1% primary validate=no
netsh int ipv4 add dns name="%INTERFACE%" %DNS2% index=2

:end
ipconfig /flushdns
ipconfig /all
pause

Step 2: RUN IT!

To change the DNS, you'll need to run it as administrator. 

You'll see something like below. Just choose the option and press enter. Then Press any key to close the command window.


That's it. You can double check your DNS setting and make sure it's changed. And now changing DNS is just 2 clicks away. 




No comments:

Post a Comment