How to make Windows send specific traffic to specific ethernet ports?
In my line of work, I am often in a situation where I want to do this:
Icon made by Freepik used with permission from flaticon.com
Essentially, I have my phone setup as a Wifi hot-spot, in order to download license and firmware files from an online server, and write those files to a TCP/IP device that I have hard-wired to my PC. This process is much easier if I can have both Wifi and Ethernet active at the same time. Basically, the TCP/IP device can find it's own appropriate firmware on the server if I have internet, otherwise I'm forced to disable the Ethernet port, manually locate and download the file, disable the Wifi, Enable the Ethernet port, and finally reconnect to my device and manually upload the files.
The problem is, Windows (specifically, Windows 7) doesn't understand how to use multiple adapters, especially if my Ethernet connection is not a direct connection but rather routes through an internal network (that still doesn't have internet access).
Is there any way to set up something like a routing table in Windows 7, i.e. set it up so that "packets from X address range go to Y adapter, otherwise send packets on Z adapter"? If I can't route by destination address, could I at least associate a specific adapter with a specific application?
You can set up something not just like a routing table, but exactly a routing table.
From an elevated command prompt in Windows, you can use the command ROUTE
.
You can see your current route table and interfaces using route print
.
I frequently use a similar set up, where my VPN only connects via my mobile phones carrier and not by my WiFi. As such, I set up my routing table by:
route delete 0.0.0.0
- Gets rid of the default routes once I've connected my to my phones hotspot, as it'll usually set up two and they'll both handle it with different metrics. Metrics determine the priority of a route, the lower the number, the higher the priority.
route add 0.0.0.0 mask 0.0.0.0 192.168.44.1 if 5
- Sets up a new default route for all otherwise unhandled traffic, pointing at 192.168.44.1 (The gateway of my phones hotspot), using interface 5, which is the Bluetooth PAN device of my machine found by looking in route print
.
I can then connect to VPN, delete the 0.0.0.0
route again, and re-add the route to my WiFi. Finally, I can use:
route add 192.168.0.0 mask 255.255.255.0 192.168.13.11 IF 58
- This points all traffic to a 192.168.0.X subnet to the gateway of the VPN server, using the VPN interface.
Once this is completed, all 192.168.0.X traffic is sent to the VPN server. Any other, non specifically routed traffic, is then handled by the 0.0.0.0 mask,
Of course, all of this will vary based on your hardware and network layout, but it can certainly be done.
Further reading:
ROUTE - Routing table
The majority of the people simply try to add an alias IP on tcp/ip configuration G.U.I., windows will not handle it well.
Adding a route using a correct metric and setting the correct interface (IF param) can be the solution. On Command prompt type the following (adapting the addresses, metric and interface number to your real scenario):
route ADD 192.168.3.0 MASK 255.255.255.0 192.168.3.1 metric 2 if 2
To get the interface number of an adapter use the command route print
, it will show a section of interfaces, something like this:
================
Interface List
4... ......Bluetooth Device (Personal Area Network)
3... ......Intel(R) Wireless WiFi Link 4965AG
2... ......VMware Virtual Ethernet Adapter for VMnet1
...
Source: Microsoft ROUTE command line tool manual
---- EDIT ----
As stated by Phoebus here, an netsh route adding can be more efficient, the approach is the same of route.exe command. If you read the article about routing table contained on Jonno answer to this question will be very easy to you manage both netsh route and route.exe
netsh route manual is here