Force Internet connection to desired network adapter

PROBLEM:

Working in an IT company, you may be familiar with the situation where you have 2 network interfaces connecting to 2 different networks (or even a same network). Sometimes you want traffic going through one specific interface but not through the other. You are not sure and you switch off one interface to avoid the problem. That's okay but it's kind of annoying.

SOLUTION:

I faced the same problem. I did some research and found this help. Let's summarize it.
Windows decides which interface to handle which traffic based on a routing table. To see it issue command route print on cmd terminal. You will get something like below.

Currently, I don't connect my wire cable so there is only one record for destination 0.0.0.0. If there are more than one with 0.0.0.0, then the one with the lowest metric will be used. (0.0.0.0 matches every IP address). Usually, if you want to route internet traffics, you should change the 0.0.0.0 record. For other networks, specify the right combination of Network Destination and Netmask.

There is no way to edit a record in the table directly. We must delete and re-create it.

route delete <network destination> if <number of wanted interface>
route -p add <network destination> mask <netmask> <ip of gateway> metric <metric number> if <number of wanted interface>

The -p switch makes it permanent. Metric 1 will give it the lowest cost. Number of interface is the number displayed in the first column of Interface List in the output of route print.

Comments