机器有个USB无线网卡和有线网卡,当有线网卡空着,无线网卡可以链接无线路由上网。而一旦此时把有
线网卡接入另一个网络,之前通过无线网卡的链接就断开了。
这是由于windows更改了网关的地址,优先使用有线网卡的网关。
通过route print(运行CMD,然后输入route print)命令可以看到本机网络的路由分配情况:
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0xa0004 ...00 0f 02 e0 2a b3 ...... Realtek RTL8187 Wireless 802.11b/g 54Mbps USB 2.0 Network Adapter - 数据包计划程序微型端口
0xb0003 ...00 23 5a 84 c4 c7 ...... Atheros AR8121/AR8113/AR8114 PCI-E Ethernet Controller - 数据包计划程序微型端口
===========================================================================
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.107 25
0.0.0.0 0.0.0.0 192.168.22.191 192.168.22.112 20
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.1.0 255.255.255.0 192.168.1.101 192.168.22.112 20
192.168.1.0 255.255.255.0 192.168.1.107 192.168.1.107 25
192.168.1.101 255.255.255.255 127.0.0.1 127.0.0.1 20
192.168.1.107 255.255.255.255 127.0.0.1 127.0.0.1 25
192.168.1.255 255.255.255.255 192.168.1.101 192.168.22.112 20
192.168.1.255 255.255.255.255 192.168.1.107 192.168.1.107 25
192.168.22.0 255.255.255.0 192.168.22.112 192.168.22.112 20
192.168.22.112 255.255.255.255 127.0.0.1 127.0.0.1 20
192.168.22.255 255.255.255.255 192.168.22.112 192.168.22.112 20
224.0.0.0 240.0.0.0 192.168.1.107 192.168.1.107 25
224.0.0.0 240.0.0.0 192.168.22.112 192.168.22.112 20
255.255.255.255 255.255.255.255 192.168.1.107 192.168.1.107 1
255.255.255.255 255.255.255.255 192.168.22.112 192.168.22.112 1
Default Gateway: 192.168.22.191
===========================================================================
Persistent Routes:
None
其中关键的是:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.107 25
0.0.0.0 0.0.0.0 192.168.22.191 192.168.22.112 20
192.168.1.107 是无线网卡的IP,网关是192.168.1.1
192.168.22.112 是有线网卡的IP,网关是192.168.22.191
Metric 表示网络选择优先值,越小越优先。
因此此时的网络网关是有线网卡的网关192.168.22.191
可以通过rotue命令来修改:
route ADD 0.0.0.0 MASK 0.0.0.0 192.168.1.1 METRIC 10 IF 0xa0004
命令解释:
增加一条路由记录,网关是192.168.1.1,METRIC 是10,IF是Interface,也就是对应的网卡序号,对应route print 中的Interface List第一列值(每次有新网络硬件改动这个值都会变动)
tips:
直接输入route 可看帮助
route -f 可以清除手工设置的路由
这样即可保持Internet网络还是使用无线网络的,而有线网络也可以使用。
因为网口要用来调试,所以搞了个D-Link上网,可以本地连接上后,就没办法无线上网了。好在看到了这篇文章:
http://hi.baidu.com/rainchen/item/54ee82613b9489147cdecce6