您的位置:首页 > 其它

Windows 中在多网卡系统中指定网卡的优先使用顺序

2011-07-05 21:51 579 查看
看见以下这个帖子,为了有线LAN连接和无线WLAN连接搞的很烦,感觉回答者也不得要领。总结整理了一下,记录在这里。
http://social.microsoft.com/Forums/zh-CN/window7betacn/thread/0e95dc43-dac9-4f0c-ba67-88e381dc3f9f

多网卡系统中,尤其在办公室中,确实是不应该使用无线连接,应该自动优先使用有线连接来保证客户端和网络两方面的性能。但是这要在客户端设置。 MS 有一个KB详细介绍了设置方法: http://support.microsoft.com/kb/894564

基本原理就是 给每个绑定了 TCP/IP的网络连接指定不同的权重,这样在Windows的路由表中,每个网卡对应的路由就有不同的权重,Windows就会优先使用低权重的路由(网络连接)了。具体操作就是 WMI 的 Win32_NetworkAdapterConfiguration 类有一个属性 IPConnectionMetric ,给无线网络连接实例的这个属性赋予 较高的权重值即可。

http://msdn.microsoft.com/en-us/library/aa394217(v=vs.85).aspx MSDN 中描述的很详细,重要部分摘录如下

Cost of using the configured routes for the IP bound adapter and is the weighted value for those routes in the IP routing table. If there are multiple routes to a destination in the IP routing table, the route with the lowest metric is used. The default value is 1.
Windows 2000: This property is not available. --------- 注意 Win 2000上不能用,没这个属性。

有通过注册表的方法,和通过WMI 脚本两种方法,KB中都描述的很详细,建议有兴趣的朋友自行研究测试。注册表方法比较繁琐,还是脚本方法比较适合企业环境,所以我摘录如下

==== snip - Start of script code Set_Wireless_NIC_IPMetric.vbs script ====
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

regValueDataMetric = "35"

Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter Where NetConnectionID = 'Wireless Network Connection'")

For Each objItem in colItems
strMACAddress = objItem.MACAddress
Wscript.Echo "MACAddress: " & strMACAddress
Next

Set colNetCard = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetCard in colNetCard
If objNetCard.MACAddress = strMACAddress Then
For Each strIPAddress in objNetCard.IPAddress
Wscript.Echo "Description: " & objNetCard.Description
Wscript.Echo "IP Address: " & strIPAddress
Wscript.Echo "IPConnectionMetric: " & objNetCard.IPConnectionMetric
objNetCard.SetIPConnectionMetric(regValueDataMetric)
Next
End If
Next
==== snip - End of VBS script ====
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐