實現Qemu aarch32虛擬開發板ping www.baidu.com

環境

Qemu: 2.8.0express

開發板: vexpress-ca9網絡

 

概述

若是要玩物聯網,至少應該讓開發板實現聯網,讓qemu支持聯網在以前的博文中已經有介紹了,可是若是隻能在本身的局域網內玩耍就太沒意思了,下面就實現用開發板ping百度, 能夠參考tq2440的根文件系統。ide

 

正文

1、下面是個人路由器配置測試

WAN口的狀態不用關心,只關心LAN口就能夠了:
網段: 192.168.1.0
網關: 192.168.1.1
子網掩碼: 255.255.255.0
個人PC經過網線鏈接到路由器上面,路由器開啓了DHCP服務, 也能夠認爲Qemu虛擬出來的開發板也直連到路由器上面了。
2、要實現ping www.baidu.com就涉及到域名解析
這裏咱們直接拷貝PC的resov.conf文件:
1 { pengdonglin@pengdonglin-dell /home/pengdonglin }
2 $cat /run/resolvconf/resolv.conf 
3 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
4 #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
5 nameserver 202.106.195.68
6 nameserver 202.106.0.20

咱們在開發板的/etc下建立resolv.conf,內容以下:this

1 [root@vexpress ~]# cat /etc/resolv.conf 
2 nameserver 202.106.195.68
3 nameserver 202.106.0.20
3、在開發板的/etc下面建立net.conf文件
1 [root@vexpress ~]# cat /etc/net.conf 
2 IPADDR=192.168.1.3
3 NETMASK=255.255.255.0
4 GATEWAY=192.168.1.1
5 MAC=52:54:00:12:34:56

4、建立/etc/hosts文件spa

1 [root@vexpress ~]# cat /etc/hosts 
2 localhost               127.0.0.1
5、編寫網絡設置腳本net_set
 1 #!/bin/sh
 2 
 3 source /etc/nettype.conf
 4 source /etc/net.conf
 5 
 6 ifconfig eth0 down
 7 ifconfig eth0 hw ether $MAC
 8 echo ifconfig eth0 hw ether $MAC >/dev/console
 9 
10 ifconfig eth0 $IPADDR netmask $NETMASK up
11 echo ifconfig eth0 $IPADDR netmask $NETMASK up >/dev/console
12 
13 route add default gw $GATEWAY
14 echo add default gw $GATEWAY >/dev/console
6、修改開機腳本/etc/init.d/rcS
 1 #!/bin/sh
 2 
 3 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 4 runlevel=S
 5 prevlevel=N
 6 umask 022
 7 export PATH runlevel prevlevel
 8 mount -a
 9 mkdir -p /dev/pts
10 mount -t devpts devpts /dev/pts
11 echo /sbin/mdev > /proc/sys/kernel/hotplug
12 mdev -s
13 mkdir -p /var/lock
14 
15 mount -t ext4 /dev/mmcblk0p2 /root
16 
17 modules_dir=/lib/modules/`uname -r`
18 
19 if [ ! -d ${modules_dir} ];then
20     mkdir -p ${modules_dir}
21 fi
22 
23 if [ ! -d /d ]; then
24     ln -sf /sys/kernel/debug /d
25 fi
26 
27 ifconfig lo 127.0.0.1
28 net_set 29 
30 /bin/hostname -F /etc/sysconfig/HOSTNAME
31 if [ -e /usr/sbin/telnetd ]; then
32     telnetd&
33 fi
7、測試
 1 [    7.248250] smsc911x 4e000000.ethernet eth0: MAC Address: 52:54:00:12:34:56
 2 ifconfig eth0 hw ether 52:54:00:12:34:56
 3 [    7.367408] Generic PHY 4e000000.etherne:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=4e000000.etherne:01, irq=-1)
 4 [    7.394043] smsc911x 4e000000.ethernet eth0: SMSC911x/921x identified at 0xf1390000, IRQ: 31
 5 ifconfig eth0 192.168.1.3 netmask 255.255.255.0 up
 6 add default gw 192.168.1.1
 7 Please press Enter to activate this console. 
 8 [root@vexpress ]# 
 9 [root@vexpress ]# route -n
10 Kernel IP routing table
11 Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
12 0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
13 192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
14 [root@vexpress ]# 
15 [root@vexpress ]# ping www.baidu.com
16 PING www.baidu.com (61.135.169.121): 56 data bytes
17 64 bytes from 61.135.169.121: seq=0 ttl=56 time=6.315 ms
18 64 bytes from 61.135.169.121: seq=1 ttl=56 time=4.089 ms
19 64 bytes from 61.135.169.121: seq=2 ttl=56 time=4.387 ms
20 64 bytes from 61.135.169.121: seq=3 ttl=56 time=4.112 ms
21 ^C
22 --- www.baidu.com ping statistics ---
23 4 packets transmitted, 4 packets received, 0% packet loss
24 round-trip min/avg/max = 4.089/4.725/6.315 ms
25 [root@vexpress ]# 

能夠經過route -n或者route -e查看當前的路由表。debug

 
完。
相關文章
相關標籤/搜索