Monday, November 30, 2015

How to control wireless vs wired priority in Windows

A Student asked recently how to control wireless vs. LAN priorities in Windows 7. Wireless was being used, even when on the LAN. One absolute way to do this is by disabling the Wireless when connected to the LAN – but this requires vendor support – like in some Dell BIOS’ there’s an option to do this. But a simpler method may be to override the default interface metric used by IP on the wired or wireless interface. Here's the what and why and how: 

If I go to the route print command on a system with wired and wireless I see the following :

I’ve highlighted the two interface IPs which show their bizarre local on-link metrics for local communications. (FWI, these are all derived from what we will be configuring directly)  What really matters here is the metric to the default gateway routes circled at the top – which one will be used?

In my case will be used with the metric of 20. How did it get that metric of 20? It’s certainly not 20 hops to the default gateway! Well a metric does not mean hop count. A metric is the just the relative measure to determine preference among routing methodologies.
Well, as we would learn from the metric for each interface to the default gateway is based upon a link speed range:

Link Speed Metrics for Operating Systems after XP sp2
10 = > 200 Mb 
20 = Between 80 Mb and 200 Mb 
25 = Between 20 Mb, and 80 Mb 
30 = Between 4 Mb, and 20 Mb 
40 = Between 500 Kb and 4 Mb 
50 = < 500 Kb 
So in my scenario it’s because it has the Link speed of 100mb/s which gives it an automatic metric of 20, which is better than the which has a link speed of 72mb/s (wireless) which earns it an automatic metric of 25. So in my scenario, the LAN is preferred over the Wireless, and all is well.

The real problem shows up with a 802.11n interface that gets about 150mb/s and a LAN interface with 100mb/s. Then they both get a metric of 20, and it’s a toss up which one gets used, and you may find that it's the wireless!

This is the situation when you will override the automatic metric by going to the advanced interface property dialog box of the TCP/IP settings to lower the metric of the preferred NIC (or raise the metric of the the less preferred NIC)

In my scenario, I'm lowering the metric of my Wireless to force it to be the preferred Interface.  After making this change, we can see that the default gateway is now preferred to go through this interface that his this metric.
I’m going to undo this now so that my LAN is the preferred interface again!

Hopefully this deepens your understanding of how Microsoft is managing your multihomed system when it comes to routing. And these are really routing rules that apply to all routing devices and protocols as well, so this knowledge can serve you when administering any routing device and managing two routes to the same network based on the same protocol with differing metrics.

Good luck getting Windows to behave itself!

No comments: