Created
March 15, 2025 08:21
-
-
Save cuongitl/963f551fea2832846eb31e3a15ae772d to your computer and use it in GitHub Desktop.
Batch Script to Change/Remove DNS Servers
This file contains hidden or 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
| :: Filename: install-vnstat.sh | |
| :: Modified: 2025-01-02 | |
| :: Purpose: Quick remove/set DNS servers for a network card. | |
| :: Built with ❤️ by Cuongitl (https://t.me/Cuongitl) | |
| @echo off | |
| SET NETWORK_CARD=Ethernet | |
| echo Network interface modification script | |
| echo Current interface: %NETWORK_CARD% | |
| echo. | |
| echo 1. Set DNS to 127.0.0.1 | |
| echo 2. Set DNS to Google Public DNS | |
| echo 3. Remove DNS settings (reset to DHCP) | |
| echo. | |
| choice /C 123 /M "Select an option" | |
| :: Note - list ERRORLEVELS in decreasing order | |
| if errorlevel 3 goto :REMOVE_DNS | |
| if errorlevel 2 goto :SET_GOOGLE | |
| if errorlevel 1 goto :SET_DNS_LOCAL | |
| :SET_DNS_LOCAL | |
| echo Setting DNS server to 127.0.0.1 on %NETWORK_CARD%... | |
| netsh interface ip set dns name="%NETWORK_CARD%" source=static addr=127.0.0.1 | |
| if %errorlevel%==0 ( | |
| echo DNS successfully set to 127.0.0.1 | |
| ) else ( | |
| echo Failed to set DNS - make sure to run as administrator | |
| ) | |
| goto :END | |
| :SET_GOOGLE | |
| echo Setting DNS server to Google on %NETWORK_CARD%... | |
| netsh interface ip set dns name="%NETWORK_CARD%" source=static addr=8.8.8.8 primary | |
| if %errorlevel% neq 0 ( | |
| echo Failed to set primary DNS to 8.8.8.8 - make sure to run as administrator | |
| goto :END | |
| ) | |
| :: netsh interface ip set dns name="%NETWORK_CARD%" source=static addr=8.8.4.4 | |
| netsh interface ip add dns name="%NETWORK_CARD%" addr=8.8.4.4 index=2 | |
| if %errorlevel%==0 ( | |
| echo DNS successfully set to Google Public DNS (8.8.8.8 and 8.8.4.4) | |
| ) | |
| goto :END | |
| :REMOVE_DNS | |
| echo Removing DNS server settings from %NETWORK_CARD%... | |
| netsh interface ip set dns name="%NETWORK_CARD%" source=dhcp | |
| if %errorlevel%==0 ( | |
| echo DNS settings successfully reset to DHCP | |
| ) else ( | |
| echo Failed to reset DNS - make sure to run as administrator | |
| ) | |
| goto :END | |
| :END | |
| echo. | |
| pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment