Windows 设置永久路由和跃点数
在我的电脑上, 遇到了需要有线和无线同时使用的情况: 使用有线连接外网, 使用无线连接机器人; 由此出现了路由的问题, 在此做一说明
Caution: 此方法我尝试失败, 但是该种经验还是需要去记录; 理论效果并不代表实际情况, 请慎重考虑!!!
Windows 网络跃点数 (未经查证!!!):
| 接口类型 | 默认跃点数 |
|---|---|
| 有线网卡(以太网) | 20 |
| 无线网卡(Wi-Fi) | 30 |
| 移动热点/蜂窝网络 | 50 |
| 环回接口(loopback) | 1 |
| 隧道接口(VPN等) | 通常 5 或手动设置 |
route -p add 添加路由时手动设置跃点数的语法:
1
route -p add 目标网络 mask 子网掩码 网关 metric 跃点数
具体示例:
# 添加永久路由,跃点数设为 5
route -p add 192.168.10.0 mask 255.255.255.0 10.0.1.1 metric 5
# 添加默认路由,跃点数设为 10
route -p add 0.0.0.0 mask 0.0.0.0 192.168.1.1 metric 10
Windows 查看当前跃点数:
1
netsh interface ipv4 show interface
例如:
Idx Met MTU 状态 名称
--- ---------- ---------- ------------ ---------------------------
1 75 4294967295 connected Loopback Pseudo-Interface 1
20 45 1500 connected WLAN
19 20 1500 disconnected 以太网
21 25 1500 disconnected 本地连接* 2
13 35 1500 connected VMware Network Adapter VMnet1
4 35 1500 connected VMware Network Adapter VMnet8
47 15 1500 connected vEthernet (WSL)
Windows 设置当前跃点数 (以 “以太网” 为例):
1
netsh interface ipv4 set interface "以太网" metric=20
Note: 该处跃点数并不代表最终跃点数; 最终跃点数 = 接口跃点数(可设置) + 网关跃点数
Windows 确认路由优先级 (最终跃点数):
1
route print -4 | findstr 0.0.0.0
例如:
C:\Users\songs>route print -4 | findstr 0.0.0.0
0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.161 50
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.2 40
224.0.0.0 240.0.0.0 在链路上 127.0.0.1 331
224.0.0.0 240.0.0.0 在链路上 192.168.1.2 276
224.0.0.0 240.0.0.0 在链路上 192.168.0.161 306
224.0.0.0 240.0.0.0 在链路上 169.254.234.131 291
224.0.0.0 240.0.0.0 在链路上 169.254.234.61 291
224.0.0.0 240.0.0.0 在链路上 172.31.224.1 271
Windows 设置禁用自动跃点, 强制设置跃点数(以 “以太网” 为例):
1
netsh interface ipv4 set interface "以太网" metric=20 ignoredefaultroutes=enabled
本文由作者按照
CC BY 4.0
进行授权