1

I have a Windows 10 machine which, for reasons, must be connected to a LAN and a WiFi simultaneously, most of the time, and only to one of them on occasion. Now, I would like the WiFi to be the default route, and the LAN to only be used for addresses in some subnet.

The subnet part is easy:

route -p ADD 192.168.0.0 MASK 255.255.0.0 192.168.0.1 METRIC 10

or a similar command will persist the routing rule of preferring the LAN for traffic to 192.168.0.0/24. You run this once and forget about it.

My problem is with the default route. I can't persist a default route to the WiFi, since sometimes it's simply invalid; while the LAN rule, while sometime invalid, never clashes with anything, since when it's invalid I can't access that LAN anyway.

I would like to either tell the OS, once and for all "Prefer this WiFi network / this WiFi adapter for defining the default route", or alternatively, find some hook for a command to run after the WiFi is connected, which I will use to write something like:

route DELETE 0.0.0.0 MASK 0.0.0.0 192.168.0.1 METRIC 35

(or whatever the default route via the LAN looks like.)

How can I achieve that?

einpoklum
  • 10,666

1 Answers1

2

Open the "old" network adapters page through ncpa.cpl, then open one adapter's Properties → TCP/IPv4 → Advanced. Uncheck the Automatic metric option and enter your preferred metric value. This won't remove the unwanted Ethernet default route, but setting it to have higher metric than the equivalent Wi-Fi route will prevent it from being chosen.

This should only affect the default route, as 'longer prefix length' is considered before 'lower metric' so a /16 route will still be chosen before any /0 route. (Your example netmask is a /16, not /24.)

grawity
  • 501,077