This question is extremely old but as I haven't seen any easy automated solution to this anywhere, I think I should share this
.cmd script I made couple of years ago.
Windows makes assumption that LAN is always faster and better than WiFi and WiFi is always faster and prettier than any mobile broadband... even in this age and time we have 3G and 4G – soon 5G.
Any of the other answers doesn't cover all these issues:
metric value for the desired
Default Gateway manually, whether you use GUI or CLI, gets extremely annoying: every time you connect to mobile network it will be reset back to the default value.
- Sometimes you don't have access to change the settings of the router.
- If the LAN / WiFi is working correctly (as it should in Enterprise environments), it will break something for other network users if you don't do this on local machine level.
This little script:
Takes Mobile Broadband by interface name. (Change to match your needs!)
Default Gateway (through interfaces
Idx) from the outputs of commands
netsh interface ipv4 show interfaces
netsh interface ipv4 show config <Idx>
metric value of that gateway to
5 in the Route Table.
Prints the modified Route Table at the end to be sure it worked.
Remember to run this
.cmd script with administrative privileges.
@set MyImportantInterface="Mobile Broadband"
@for /F "tokens=1" %%* in (
'netsh interface ipv4 show interfaces
^| findstr /R /C:%MyImportantInterface%'
) do @set /A IfIdx=%%*
@if %IfIdx% EQU 0 (
echo Interface %MyImportantInterface% not found!
echo Check the configuration on the first line of this script.
exit /B 1
@for /f "tokens=3" %%* in (
'netsh interface ipv4 show config %IfIdx%
^| findstr /R /C:"Default Gateway"'
) do @set TheDefaultGateway=%%*
@route PRINT | findstr /r /c:"^Network" /c:"[ ]0.0.0.0"
@echo Trying to lower the metric of %MyImportantInterface% (Idx %IfIdx%)...
@route CHANGE 0.0.0.0 MASK 0.0.0.0 %TheDefaultGateway% ^
METRIC 5 IF %IfIdx%
@if %ERRORLEVEL% GEQ 1 exit /B 5
@route PRINT | findstr /c:"%TheDefaultGateway%"