Last active
April 11, 2019 12:15
-
-
Save abakum/60a865aa8637b1de8c701f57e0c0671e to your computer and use it in GitHub Desktop.
Via netsh set GATE and list of NS for uplink interface UP
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
@echo off | |
echo This script via netsh set GATE and list of NS for uplink interface UP | |
echo Rename or mklink this script with real value where: | |
echo UP is name of uplink interface | |
echo If GATE omitted then IP, GATE and NS will be received from DHCP | |
echo If NS omitted then GATE is NS | |
echo After NS2 there may be NS3 and so on | |
echo This script via setx set global environment values: uplink as UP and gate as GATE | |
cd /d %~dp0 | |
call :ip %~n0 | |
ipconfig /flushdns | |
ipconfig /all | |
ping -n 1 ya.ru | |
tracert -4 -d -h 1 ya.ru>gate | |
type gate | |
setx gate /f gate /a 4,7 | |
pause | |
goto :EOF | |
:ip | |
set uplink=%1 | |
shift | |
netsh interface ip delete route prefix=0.0.0.0/0 interface=%uplink% | |
if errorlevel 1 ( | |
netsh interface ip show interfaces>uplink | |
setx uplink /f uplink /a 4,4 | |
) else ( | |
setx uplink %uplink% | |
) | |
set gate=%1 | |
if defined gate ( | |
shift | |
netsh interface ip add route prefix=0.0.0.0/0 interface=%uplink% nexthop=%gate% publish=yes | |
) else ( | |
netsh interface ip set address name=%uplink% source=dhcp | |
goto :EOF | |
) | |
set ns=%1 | |
if defined ns ( | |
shift | |
) else ( | |
set ns=%gate% | |
) | |
netsh interface ip set dnsservers name=%uplink% source=static address=%ns% | |
set index=1 | |
:ns | |
set ns=%1 | |
if not defined ns goto :EOF | |
shift | |
set /a index=index+1 | |
netsh interface ip add dnsservers name=%uplink% index=%index% address=%ns% | |
goto :ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
netsh interface ip show interfaces>interfaces
SETX uplink /f interfaces /a 4,4
mklink "%CD%\%uplink% 192.168.0.1 77.88.8.8 8.8.8.8 77.88.8.1.bat" "%CD%\UP GATE NS NS2.bat"