windows 10 切换WIFI和网线的优先级

在办公室里需要同时连接网线和 WIFI:网线连通公司内网,WIFI 连接外网。手动切换比较麻烦,手动配置路由也比较麻烦。

查询了一下,发现可以通过设置网络的优先级来实现切换默认网络,可以用 PowerShell 来执行。

查看当前网络接口

管理员模式运行 PowerShell,获取网络列表,过滤出 IPv4 且连接状态的网络:

1
2
3
4
5
6
7
PS C:\Users\JinlohWu> Get-NetIPInterface -AddressFamily IPv4 -ConnectionState Connected

ifIndex InterfaceAlias AddressFamily NlMtu(Bytes) InterfaceMetric Dhcp ConnectionState PolicyStore
------- -------------- ------------- ------------ --------------- ---- --------------- -----------
20 Ethernet IPv4 1500 45 Enabled Connected ActiveStore
21 Wi-Fi IPv4 1500 95 Enabled Connected ActiveStore
1 Loopback Pseudo-Interface 1 IPv4 4294967295 75 Disabled Connected ActiveStore

调整优先级

然后调整 WIFI 的优先级:

1
2
PS C:\Users\JinlohWu> Set-NetIPInterface -InterfaceIndex 21 -InterfaceMetric 95
PS C:\Users\JinlohWu> Set-NetIPInterface -InterfaceIndex 21 -InterfaceMetric 5
  • -InterfaceIndex 指的是第一个命令结果中网卡的索引号
  • -InterfaceMetric 用于指定接口跃点数:数值越小,优先级越高,优先级高就会变成首选网络

小结

通过把 WIFI 网络的跃点数调成 95 或 5,这两条命令的交替执行就能达到 WiFi 网络和有线网络交替成为默认网络,状态栏的网络图标的变换可能稍有延迟。

Notice: 正常情况下,这里会有一个基于utteranc.es的留言系统,如果看不到,可能要想想办法才能看到。

Powered by Hexo and Hexo-theme-hiker

Copyright © 2012 - 2026 tiaobug.com All Rights Reserved.

鲁ICP备2024124237号-1