Page 1 of 1

Redirect Network Traffic Over A Specific Interface route ADD and Changing Interface Metrics Rate Topic: ***** 1 Votes

#1 homemade-jam  Icon User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Posted 22 March 2010 - 04:02 AM

Introduction
So, the other day I wanted to transfer some files over my ethernet interface to another computer in the house...however Windows insisted that it use the WiFi which gave speeds of 50kb/s. This seemed pretty strange seeing as there was an obvious Ethernet connection to the same computer with significantly higher speeds!

Whatsmore, when I tried to go on the internet nothing resolved as it was trying to use the ethernet which didn't have an internet connection.

This will be done in two stages:
  • First getting the internet back by reducing the metric of the wifi interface so that it has a higher precedence over the internet free ethernet interface.
  • Second, getting a route added into the routing table to tell windows to send all data to a particular IP address over a specific interface



Network Interface Metric
For each network interface there is a 'metric' assigned that tells you the precedence of that network interface over the others - with the two interfaces (Ethernet & Wifi) the Ethernet has a lower metric as it is faster. Therefore, the ethernet has higher precedence over the Wifi for internet connection. Not what I wanted!

So, a simple way to fix this is set the metric manually for each interface. In command prompt it is possible to view the automatic metric assigned to each interface by windows. In cmd type the following route print. For me this yielded the following results:
Interface List
This tells you all about the mac address and names for each NIC and some other virtual cards that can be ignored. We won't be using the information from this section of the output but it could be useful for you in the future.
(I've changed my mac address' to something different just for security)
===========================================================================
Interface List
 16...00 16 b6 5a aa aa ......Linksys Wireless-G USB Network Adapter
 11...00 16 76 aa aa aa ......Intel(R) 82562V 10/100 Network Connection
  1...........................Software Loopback Interface 1
 12...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
 13...00 00 00 00 00 00 00 e0 Microsoft 6to4 Adapter
 14...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
 15...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
===========================================================================


In my example the default gateway for the ethernet connection is 192.168.1.1. This is just a router connected to my other computer to which I want to transfer the files.
The wifi gateway is 192.168.1.254: a wireless router connected to the internet.
IPv4 Route Table
After the interface list is the juicey part: the route table. This tells you the metric for each interface and the default gateway. Depending on the number of interfaces you have (in our example we only have to) you will have a line detailing the active routes. Here is the example one, with the automatic metrics:
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface            Metric
0.0.0.0                    0.0.0.0          192.168.1.254     192.168.1.67     80
0.0.0.0                    0.0.0.0	    192.168.1.1	      192.168.1.64     60

So, the first line is for the wireless interface with the default gateway and interface IP address. As you can see, the wireless interface has a higher metric than the ethernet interface...windows will default to the ethernet when you try and access the internet.

Right about now you might ask why the ethernet has higher precedence than the wifi for internet but not internal file sharing. I'm afraid I'm at a bit of a loss to explain. If anyone has any ideas I would be very interested to know!

Anyway, now you can see what metric the OS has supplied to each of your interfaces. All you need to do is switch them round so that you can get the internet back! To do this is fairly straight forward...
Type ncpa.cpl into the run box. (Windows key + r). This will bring up the network interfaces available on your computer. Mine looked something like this...[image]http://www.windowsre...images/me/2.PNG[/image].
First we will adjust the metric for the wifi card down from 80 to 60...right click the Wifi Card then click properties (you will be asked to be an administrator at some point...click allow). In the properties screen you will be greeted by the list of protocols that the interface handles...we want to adjust the IPv4 protocol settings:Attached Image
Click properties (with the IPv4 settings higlighted) and then click the advanced button on the bottom right hand side. At the bottom of that page there will be an tick box set to "Automatic Metric" which lets the OS choose the metric of the interface.
Uncheck the box and type in the metric of the OTHER interface from the route print command - this will vary depending on network environment.

Repeat this process again but for the ethernet interface...typing in the original metric of the wifi interface.

Ok, just to recap. We now have the wifi with a higher precedence over the ethernet. This fixes our internet connectivity problem but still leaves us with the fact that the file sharing traffic to the other computer will still be routed over the wifi.

Adding A Route
To fix the problem of routing traffic over a specific interface, we need to add a line to our route table.
This must be done from an administrator command line session. Navigating to C:\Windows\System32 and right clicking the cmd.exe icon and choosing "Run as administrator" should do the trick (the directory of cmd.exe may vary between OS versions and whether or not your computer is 32 or 64 bit).
From this we will use the route -p add DestinationIP mask subnet InterfaceGatewayIP command with the following parameters:
  • -p makes the routing permanent otherwise you will lose the routing rule at the next reboot. Feel free to omit this argument.
  • The destinationIP is the IP address of my other computer ON THE WIRED NETWORK(!!) rather than on the wifi network. These two IP should differ. If they don't then you will need to change the IP to something different (beyond the scope of this tutorial).
  • Next, simply type mask
  • Then type 255.255.255.255 this tells you that the subnet is irrelevent - you don't mind.
  • Finally, you want to tell route which default gateway you would like to send the traffic for that particular set of data. i.e. This is the IP address of my wired ethernet router - I wish to send all the traffic to the wired router if the destination IP address is equal to that of the other computer.


So, in our example I would type:
route -p add 192.168.1.65 mask 255.255.255.255 192.168.1.1 where 192.168.1.65 is the IP of my other computer on the Ethernet network while 192.168.1.1 is the IP of my ethernet router.

This route then gets given a lower metric than the wifi interface - this works as that metric is only lower for connections to that IP. Basically...it will attempt to contact that default gateway (the ethernet one) when I ask for that destination address then ask the wifi interface as a fallback.

My IPv4 routing table now looks something like this: (I have ommitted some On-Link connection which you can ignore for this scenario.
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0    192.168.1.254     192.168.1.67     40
...
     192.168.1.65  255.255.255.255      192.168.1.1     192.168.1.67     21

===========================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
     192.168.1.65  255.255.255.255      192.168.1.1       1
===========================================================================


Conclusion
Hopefully this tutorial has been of some use and not too specific...you can obviously tailor this for more general usage (e.g. every outgoing internet connection) and switch around the interfaces.

Let me know if you have any comments.

Jam

Is This A Good Question/Topic? 1
  • +

Page 1 of 1