分类: 嵌入式
2013-06-10 18:09:17
一般笔记本都有有线/无线两张网卡,当进行嵌入式开发,连接开发板时,平时不用的有线网卡就派上用处了。本文想达到的目的是:
1. 开发板能ping通虚拟机,目的是nfs挂在linux的文件系统
2. 虚拟机和PC机能ping通,目的是虚拟机中的gdb可以连接上jlink的gdbserver
3. 虚拟机可以上网,因为编译某些程序时,需要下载一些软件
主机:Win7 64位 旗舰版 + 无线,有线网卡
虚拟机:wmware8.0 + debian 6.0
开发板:mini2440
网线:
连接开发板和主机的网线必须是交叉网线,什么是交叉网线:
i.一头是:1白橙 2橙 3白绿 4蓝 5白蓝 6绿 7 白棕 8棕 (568B标准)
ii.一头是:1白绿 2绿 3白橙 4蓝 5白蓝 6橙 7白棕 8棕 (568A标准)
iii.交叉网线用于同口连接(如两边都是pc,或两边都是hub)
1) 无线网卡ip
上外网的无线网卡可以DHCP自由分配
2) 主机有线网卡IP设置
3) 虚拟机ip设置
/etc/networking/interfaces:
#桥接到有线网卡
auto eth1
# iface eth0 inet dhcp
iface eth1 inet static
address 192.168.2.27
netmask 255.255.255.0
gateway 192.168.2.1
# 桥接到无线
auto eth0
iface eth0 inet static
address 192.168.1.26
netmask 255.255.255.0
gateway 192.168.1.1
4) 开发板ip
gatewayip=192.168.2.1
netmask=255.255.255.0
ipaddr=192.168.2.22
serverip=192.168.2.27
四. 配置VMware网卡
VMnet0 桥接到无线网卡 ---- 对应虚拟机eth0 192.168.1.26
VMnet1 桥接到有线网卡 ---- 对应虚拟机 eth1 192.168.2.27
注意: 物理网卡要选择Custom:Specific vitual network
添加路由规则
vi /etc/rc.d/rc.local
route add -net 192.168.2.0/24 gw 192.168.0.254 dev eth1
route add -net 192.168.1.0/24 gw 192.168.0.254 dev eth0
另外双网卡导致dns不能工作,不能靠修改/etc/resolv.conf文件,因为每次重启后就会失效
正确的办法是修改/etc/network/interfaces,
添加dns:
dns-nameservers 202.99.96.68
$ sudo route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth1