29

I've searched for details on how to do this but I've been unsuccessful - I wondered if someone could offer up some advice.

So, let's say I have 2 network cards (LAN and 3G in my instance), both assigned dynamic IP addresses. The LAN interface is my corporate LAN, and I'd like to use the 3G interface for all other access (ie, t'internet!).

I have little networking experience, but my feeling is that I should be able to make the 3G card the default gateway, and then force all traffic for a set of known subnets through the LAN interface.

Here's a route print

===========================================================================
Interface List

 40...........................Vodafone Mobile Connect
 12...00 16 cf 87 71 22 ......Dell Wireless 1500 Draft 802.11n WLAN Mini-Card
 11...00 15 c5 58 47 24 ......Broadcom NetXtreme 57xx Gigabit Controller
 24...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
 25...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
  1...........................Software Loopback Interface 1
 26...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
 13...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
 21...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
 23...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #4   
 28...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #6
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
    Netork Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0     10.183.148.5   10.183.148.157   4235
          0.0.0.0          0.0.0.0     10.183.148.6   10.183.148.157   4235
          0.0.0.0          0.0.0.0     10.183.148.7   10.183.148.157   4235
          0.0.0.0          0.0.0.0         On-link      10.57.175.79     31
     10.57.175.79  255.255.255.255         On-link      10.57.175.79    286
     10.183.148.0    255.255.255.0         On-link    10.183.148.157   4491
   10.183.148.157  255.255.255.255         On-link    10.183.148.157   4491
   10.183.148.255  255.255.255.255         On-link    10.183.148.157   4491
       127.0.0.0        255.0.0.0         On-link         127.0.0.1   4531
        127.0.0.1  255.255.255.255         On-link         127.0.0.1   4531
  127.255.255.255  255.255.255.255         On-link         127.0.0.1   4531
      169.254.0.0      255.255.0.0         On-link    10.183.148.157   4511
  169.254.255.255  255.255.255.255         On-link    10.183.148.157   4491    
      192.168.6.0    255.255.255.0         On-link       192.168.6.1   4501
      192.168.6.1  255.255.255.255         On-link       192.168.6.1   4501
    192.168.6.255  255.255.255.255         On-link       192.168.6.1   4501
     192.168.73.0    255.255.255.0         On-link      192.168.73.1   4501
     192.168.73.1  255.255.255.255         On-link      192.168.73.1   4501
   192.168.73.255  255.255.255.255         On-link      192.168.73.1   4501
        224.0.0.0        240.0.0.0         On-link         127.0.0.1   4531
        224.0.0.0        240.0.0.0         On-link    10.183.148.157   4492
        224.0.0.0        240.0.0.0         On-link       192.168.6.1   4502
        224.0.0.0        240.0.0.0         On-link      192.168.73.1   4502
        224.0.0.0        240.0.0.0         On-link      10.57.175.79     31
  255.255.255.255  255.255.255.255         On-link         127.0.0.1   4531
  255.255.255.255  255.255.255.255         On-link    10.183.148.157   4491
  255.255.255.255  255.255.255.255         On-link       192.168.6.1   4501
 255.255.255.255  255.255.255.255         On-link      192.168.73.1   4501
 255.255.255.255  255.255.255.255         On-link      10.57.175.79    286
===========================================================================
Persistent Routes:
  None

So, interface 40 is my 3G card, and interface 11 is my LAN card. You can see that (I think) I have two default routes currently but the 3G wins because of the lower metric? I need to force all 10.183.. traffic over LAN interface.

Any advice is welcome !!

Regards, Jason

27

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.

  • 1
    This worked great, many thanks - although I added the -p to make it sticky! – user28599 Dec 10 '09 at 9:38
  • That's just perfect! When I faced this problem I didn't think it would be solved that quick. Just perfect, thanks. – Ashkan Jun 7 '16 at 10:20
  • The link to MS Docs is broken. :( – bahrep Nov 26 '18 at 12:53
12

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.

  • UPVOTE. My scenario was an Ethernet to a local router, 192.168.2.x and a wireless connection to a special-purpose network 192.168.6.x - and .6 was set up for instrumentation that cannot be interrupted. But they both linked back to the ISP so Netflix would then randomly decide to go over .6 when it was to stay on .2 Same with Windows file copying. So I set the IPv4 configuration of Ethernet .2 to a metric of 1 and WiFi .6 to have a metric of 100. This works great because whenever I want to talk to a .6 device there is only one way to go. But all other traffic favors Ethernet. Easy! – SDsolar Jun 6 '17 at 9:37
  • This should be the first option before anyone goes around messing with their routing tables. It can be done on each PC is just seconds, even by the hired help. Too bad the scenario in this question is not so neat and tidy. It gets complicated when both are 10.183.x.x networks. But I would bet a nickel this is a very specialized, minority case study in that regard. – SDsolar Jun 6 '17 at 9:40
5

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 
  • I haven't tried this but I thought that the IP address of the interface isn't useful because its dynamic? – user28599 Dec 10 '09 at 9:39
  • I wrote a quick n dirty vbs script that redirected the output of ipconfig command below to a file and used that value. Like so: ipconfig |findstr "IP Address 10.57" – Seamus Dec 10 '09 at 20:24
2

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.

0

Would it be easier to default route everything out the 3G card? So you would only have one route out Int 40 (with a high AD) and keep all routes on Int 11. I find it bizarre that Int 40 would have a better metric than Int 11.

Are you using dynamic routing or static routing for the whole business? I know in cisco you can place a static default route out any interface you want and then change the AD on it so you can prioritize that way.

  • I guess, you tell me :) Yes, I guess I have to have 3g card (interface 40) set to the "default" route interface. I'm not sure I either understand or can answer your second question - all I have access to is the windows 7 shell prompt :) – user28599 Dec 9 '09 at 14:59
  • Are you using a routing protocol like EIGRP, RIP or are you using all static routes? – lilott8 Dec 9 '09 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy