How to route different traffic thru different network interfaces (in Windows)

Solution 1:

The command you're looking for is route add:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/route.mspx?mfr=true

For your setup, I think the syntax is:

route add 10.183.0.0 mask 255.255.0.0 10.183.148.5

This will send all the traffic for 10.183.x.x to the next hop address of 10.183.148.5 which your system already knows is off of your ethernet nic, and any traffic that doesn't match a route, will be grabbed by your default route and head through your 3g connection. It also looks like your network assigns multiple routers, so you might want to double it up and add the routes for 10.183.148.6 and .7 as well.

You might need to be careful if your network has stuff not in the 10.183 range, you may need to add more routes. You may also be able to get away with routing all of 10.0.0.0/8 to your corporate network, since windows will have a more specific route, but i'm not 100% sure on that since your 3g card is giving you an IP in the 10.x.x.x range.

Solution 2:

An alternative way to do this is to change the 'Metric' value of each adapter in question. I have just done this with a 3G MiFi adapter. To change the Metric go into Network & Sharing Center --> Change Adapter Settings. Choose the adapter to change and go into its properties. In the advanced section of the protocol you want to change (normally IPv4) you untick the 'Automatic Metric' check box and specify your own value. The lower the value the higher priority the adapter will have when searching for a host.

This then doesnt' mess with your routing.


Solution 3:

To make the 3g card the default gateway, remove the default route of the 11 interface :

route delete 0.0.0.0 10.57.175.79

assuming that 10.57.175.79 is your LAN ip address..

Then direct your 10.183.148.x subnet to your lan ip, :

route add 10.183.148.0 mask 255.255.255.0 10.57.175.79 

Solution 4:

Changing metrics sure is better solution than deleting any of the default routes. It's also robust, since on disconnect you'd still be able to access the internet via the corporate LAN without modifications.

However, since you have dynamic IP on this interface, it's frustrating to manually find the changing gateway IP every day. Therefore, you could use this cmd script that automatically finds all the parameters needed for the ROUTE CHANGE command.

Just change the variable MyImportantInterface to meet your needs and remember to run as an administrator after establishing the 3G connection.

@echo off
REM ! CHANGE THIS TO  ! \
SET MyImportantInterface=Mobile Broadband
REM ! MATCH YOUR NEED ! /

echo Active Routes:
echo Network Destination        Netmask          Gateway       Interface  Metric

route PRINT | findstr /C:" 0.0.0.0"

echo Finding  "%MyImportantInterface%"...

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%"

As you can see, the magic happens in the two FOR loops and the ROUTE CHANGE command. The ECHOs and ROUTE PRINT commands just makes this a bit more informative. Personally I'd add a tracert command to the end to ensure it's working as I wanted. Enjoy.