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.
REM ! CHANGE THIS TO ! \
SET MyImportantInterface=Mobile Broadband
REM ! MATCH YOUR NEED ! /
For /f "tokens=1" %%* in (
'netsh interface ipv4 show interfaces
^| findstr /R /C:"%MyImportantInterface%"'
) Do Set "MyImportantInterface=%%*"
For /f "tokens=3" %%* in (
'netsh interface ipv4 show config "%MyImportantInterface%"
^| findstr /R /C:"Default Gateway"'
) Do Set "TheDefaultGateway=%%*"
route CHANGE 0.0.0.0 MASK 0.0.0.0 %TheDefaultGateway% ^
METRIC 5 IF %MyImportantInterface%
route PRINT | findstr /C:"%TheDefaultGateway%"