Hard-code network route for specific applications
4 posts · Closed
I have a Windows 11 computer with both WiFi and Ethernet. I want the Oracle VirtualBoxes to use the WiFi and I want everything else to use the Ethernet. Can Bandwidth Manager, or any of your products, let me hard-code the network route?
To achieve the goal of having Oracle VirtualBox VMs use WiFi while everything else uses Ethernet on a Windows 11 computer, you can use a combination of routing rules and interface metrics using built-in Windows feature. Here's how you can approach this:
Windows uses interface metrics to determine the priority of network interfaces. Lower metrics have higher priority. You can set the Ethernet interface to have a lower metric (higher priority) and the WiFi interface to have a higher metric (lower priority).
For that, open Network & Internet settings, click Change adapter options, right-click the Ethernet adapter and select Properties. Select Internet Protocol Version 4 (TCP/IPv4) and click Properties, then Advanced. Uncheck Automatic metric and set a low value (e.g., 10) for its interface metric. Repeat the process for the WiFi adapter and set a higher value (e.g., 20) for its interface metric. This ensures that Ethernet is preferred for general traffic, while WiFi is used as a fallback.
Now simply ensure that VirtualBox is set to use the WiFi adapter for bridged networking, and everything should work as intended.
I had been told to do the Interface metric trick before, but it still does not work. I still have traffic that should be on the Ethernet trying to get out on the WiFi. Maybe I set the values wrong? I set the low value to 0 and the high value to 1000 or something like that.
In that case you may also need to adjust the routing tables. To route all traffic through a specific interface when both Ethernet and WiFi are connected, use the route command in Windows:
Step 1
Open Command Prompt as Administrator and run:
route print
Look for the interface index (Idx) of the Ethernet and WiFi connections.
Step 2
Delete existing default routes to avoid conflicts:
route delete 0.0.0.0
Step 3
To force all traffic through a specific interface (e.g., Ethernet with gateway 192.168.1.1):
route add 0.0.0.0 mask 0.0.0.0 192.168.1.1 metric 1 if <InterfaceIndex>
Replace <InterfaceIndex> with the correct index from step 1.
Step 4
If you want the change to persist across reboots:
route -p add 0.0.0.0 mask 0.0.0.0 192.168.1.1 metric 1 if <InterfaceIndex>
Example
If Ethernet has interface index 7 and gateway 192.168.1.1, run:
route -p add 0.0.0.0 mask 0.0.0.0 192.168.1.1 metric 1 if 7
This ensures all traffic goes through Ethernet.
If you prefer a more user-friendly approach, you can use third-party tools like:
- NetBalancer: allows you to set traffic rules for specific applications or IP ranges.
- ForceBindIP: binds specific applications to a network interface.
However, the above method using route and interface metrics should suffice for your needs without additional software.