qemu树莓派桥接网络

MarsCN 2014-05-15

下载

2012-12-16-wheezy-raspbian.img

kernel-qemu

由于2012-12-16-wheezy-raspbian.img需要的内核是3.2.27+

cd/lib/modules&&ls

查看

而kernel-qemu提供的内核是3.10.26+

uname-r

查看

完全匹配的没找到,iptables不好使

root@raspberrypi:~# iptables -L
libkmod: ERROR ../libkmod/libkmod.c:554 kmod_search_moddep: could not open moddep file ‘/lib/modules/3.10.26+/modules.dep.bin’
iptables v1.4.14: can’t initialize iptables table `filter’: Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

但是不影响使用桥接网络

使用桥接连接qemu中的树莓派到网络

配置脚本放在某处,比如/root/xup

其他设置参考

http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/

[root@localhost qemu]# cat /root/xup   
#!/bin/sh  
/sbin/ifconfig $1 0.0.0.0 promisc up  
/usr/sbin/brctl addif br0 $1  
sleep 2

设置桥接网络

参考http://ju.outofmemory.cn/entry/45837

modprobe tun  
lsmod|grep tun  
ifdown eth0  
ifconfig  eth0 0.0.0.0 promisc up  
brctl addbr br0  
brctl addif br0 eth0  
brctl stp br0 off  
ifconfig br0 192.168.1.55 netmask 255.255.255.0 broadcast 192.158.1.255  
route add default gw 192.168.1.1  
ifup eth0  
启动qemu
[root@localhost qemu]# cat run.sh   
#!/bin/sh  
#qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -append "root=/dev/sda2" -hda 2012-12-16-wheezy-raspbian.img -vnc 192.168.1.111:1 -net nic -net user &  
  
#qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -append "root=/dev/sda2" -hda 2012-12-16-wheezy-raspbian.img -vnc 192.168.1.111:1 -net nic,vlan=0  &  
  
qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -append "root=/dev/sda2" -hda 2012-12-16-wheezy-raspbian.img -vnc 192.168.1.111:1 -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/root/xup  &

主机网络

[root@localhost qemu]# ifconfig  
br0       Link encap:Ethernet  HWaddr 00:0C:29:D5:D3:28    
          inet addr:192.168.1.55  Bcast:192.158.1.255  Mask:255.255.255.0  
          inet6 addr: fe80::20c:29ff:fed5:d328/64 Scope:Link  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
          RX packets:22612 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:30629 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:0   
          RX bytes:4281564 (4.0 MiB)  TX bytes:8026132 (7.6 MiB)  
  
eth0      Link encap:Ethernet  HWaddr 00:0C:29:D5:D3:28    
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0  
          inet6 addr: fe80::20c:29ff:fed5:d328/64 Scope:Link  
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1  
          RX packets:56725 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:33717 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:1000   
          RX bytes:36072369 (34.4 MiB)  TX bytes:8180253 (7.8 MiB)  
  
lo        Link encap:Local Loopback    
          inet addr:127.0.0.1  Mask:255.0.0.0  
          inet6 addr: ::1/128 Scope:Host  
          UP LOOPBACK RUNNING  MTU:16436  Metric:1  
          RX packets:162 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:162 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:0   
          RX bytes:14560 (14.2 KiB)  TX bytes:14560 (14.2 KiB)  
  
tap0      Link encap:Ethernet  HWaddr B6:94:52:0E:11:1F    
          inet6 addr: fe80::b494:52ff:fe0e:111f/64 Scope:Link  
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1  
          RX packets:320 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:527 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:500   
          RX bytes:40975 (40.0 KiB)  TX bytes:49074 (47.9 KiB)  
  
[root@localhost qemu]#

树莓派网络

root@raspberrypi:~# ifconfig  
eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56    
          inet addr:192.168.1.114  Bcast:192.168.1.255  Mask:255.255.255.0  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
          RX packets:490 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:298 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:1000   
          RX bytes:46824 (45.7 KiB)  TX bytes:37286 (36.4 KiB)  
          Interrupt:57 Base address:0x8000 DMA chan:ff   
  
lo        Link encap:Local Loopback    
          inet addr:127.0.0.1  Mask:255.0.0.0  
          UP LOOPBACK RUNNING  MTU:65536  Metric:1  
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:0   
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)  
  
root@raspberrypi:~#
 

相关推荐