Force internet connections through one specific network adapter with windows 7

For the sensorNET project, I'm using a development PC (simply my personal laptop) to develop the code for the two main components of the system, namely the main console and the client sensor boards. To do that I need to be connected to the main console on a LAN as this is the use normal users will give the system.

To that end, I connected a cable from my computer to a router. At the same time I need to keep using the internet which, in my case, is accessible through my wireless adapter. The problem is that as soon as I connect the wired network, I loose internet connectivity. As soon as I unplug the cable, the wireless internet connection resumes.

What I think is happening is that the computer routes the traffic that is meant to the internet through the wired connection whenever the connection is available. Apparently windows chooses the adapter with the wider bandwidth to route internet traffic through. How can I prevent this from happening? How can I force internet traffic through one specific adapter?

Depending on your requirements, one of the easiest ways is to go to Network Connections -> right click the wired connection icon -> choose properties -> select "Internet Protocol Version 4 (TCP/ IPv4)" -> click the "Properties" button.

Now on the window that appears, force the computer to use a specific IP address and subnet mask (in my case respectively 10.0.0.14 and 255.255.255.0) but leave the default gateway empty. If you fill in the default gateway IP with the IP of your LAN router, the wireless internet connection will still not work.

This will work. But what if I want the wired connection to use a DHCP assigned IP address? The problem is that on the "Internet Protocol Version 4 (TCP/ IPv4)" properties window, if you choose the option to Obtain an IP address automatically, the setup will not work again!

So we need another solution to the problem in case DHCP assigned IP addresses are required.

The first thing is to keep both interfaces on automatically assigned IP addresses, because this is our requirement, next issue the following command on the command prompt:

c:\ netstat -rn | more

Note the table at the top called "Interface list" and see all your NICs on the list. Just to confirm you are in the right place, see the first number on the left that is a 1 and confirm that corresponds to "Software Loopback Interface 1".

You will also note that the number on the left for your wireless adapter is higher than the one for your wired NIC. This is what makes the computer choose one or the other when both are available - the one with the lowest number is used first. We need to change the priority of the cards (or, in this case, we need to change the metric of the wireless card so that it is lower than the wired card).

Go to "Local Area Connection Properties", the properties window we used before but this time open the one for the wireless card - we want to change it's metric to make it lower than the wired card.  Select "Internet Protocol Version 4 (TCP/ IPv4)" -> click the "Properties" button -> click "Advanced..." and uncheck "Automatic metric". Insert any number lower than the number of your wired NIC but that does not yet exist on the list.

Save your changes and verify that the internet packages are now routed through the wireless connection and forever will be unless you go back on these changes.

Comments

Anonymous said…
Perfect...thanks.
Anonymous said…
Clear, direct to the point. Looked for this for ages. Thank you.
Anonymous said…
You did a great job explaining this. By the way, it works with Windows 8 also. Thanks for your help.
Doug P. said…
This works beautifully to route internet through the secondary NIC (in my case, a Wi-Fi connection to a DSL internet line).

Unfortunately for some reason when I make the Metric changes I lose access to local network shares and most network printers. Strangely, the one network printer I manually added using an IP address (instead of printer/network name).

I flushed the DNS Resolver Cache and then pinged the server by name and the IP address shown for the local server is the WAN address for the wired network.

It seems that ALL network traffic is being routed through the Wi-Fi connection, not just internet traffic.

Does anyone have any idea how to resolve this issue?
Anonymous said…
Doug you can set a manual route in your routing table. For an example my home network is 192.168.2.xxx so I do this.

route ADD 192.168.2.0 MASK 255.255.255.0 192.168.2.1 METRIC 50 IF "this is the interface number for the Internal nic. You can find this by going into a cmd window and typing route print"
Anonymous said…
Also forgot to add that you should use -p at the end to make it persistent. Meaning that it will stay if you reboot.
Unknown said…
Worked liked a charm. You're the best ;-)