Reprint: http://wiki.sylixos.com/index.php/Linux%E7%8E%AF%E5%A2%83%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97
Environment Introduction:
Win7 + Vmware + ubuntu12.04 32
U-boot version: u-boot-2015-04
Linux kernel version: LINUX-3.16.Y
BusyBox version: 1_24_stable
Cross-compilation Toolchain: arm-linux-gnueabi-
QEMU supports a variety of network links, the most common of which is bridging (bridge). This requires the support of the kernel-dependent TUN/TAP module.
- Enter the following command to install the necessary kits:
sudo apt-get install uml-utilities
sudo apt-get install bridge-utils
- Enter the following command to view the/dev/net/tun file:
ls -l /dev/net/tun
crw-rw-rwT 1 root root 10, 200 Apr 15 02:23 /dev/net/tun
If the file exists, this indicates that the kernel has support for Tun support enabled, which is enabled by default in ubuntu-12.04. If the file does not exist, you need to load the Tun module and create the/dev/net/tun file.
- To modify the/etc/network/interfaces file, the author's file contents are as follows (sample files are located in the/home/user/sylixos_workspace/qemu-mini2440/ubuntu-12.04 directory):
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
Auto lo
iface lo inet loopback
# The primary network interface
Auto eth0
#NetworkManager#iface eth0 inet dhcp
#After the experiment, it is found that since I am using a virtual machine, adding three virtual network cards eth0 corresponds to the NAT connection mode, and eth2 corresponds to the bridging mode
#If VMnet8 and VMnet1 of the virtual machine are disabled, eth2 will not work. If bridge_ports eth2 is enabled, QEMU will not be able to connect to the network
#However, it is found that eth0 is available, so the bridge? Ports eth0 is set here
Auto BR0
iface br0 inet dhcp
bridge_ports eth0
- Add/etc/qemu-ifup and/etc/qemu-ifdown scripts.
by default, when QEMU uses a tap device, both scripts/etc/qemu-ifup and/etc/qemu-ifdown are executed. We need to create these two scripts and then add executable permissions to them (using chmod +x). Create a/etc/qemu-ifup script that looks like this (the sample file is in the/home/user/sylixos_workspace/qemu-mini2440/ubuntu-12.04 directory):
#!/bin/sh
echo sudo tunctl -u $(id -un) -t $1
sudo tunctl -u $(id -un) -t $1
echo sudo ifconfig $1 0.0.0.0 promisc up
sudo ifconfig $1 0.0.0.0 promisc up
echo sudo brctl addif br0 $1
sudo brctl addif br0 $1
echo brctl show
brctl show
sudo ifconfig br0 192.168.11.20
Create a/etc/qemu-ifdown script that looks like this (the sample file is in the/home/user/sylixos_workspace/qemu-mini2440/ubuntu-12.04 directory):
#!/bin/sh
echo sudo brctl delif br0 $1
sudo brctl delif br0 $1
echo sudo tunctl -d $1
sudo tunctl -d $1
echo brctl show
brctl show
enter the following command to add executable permissions to the/etc/qemu-ifup and/etc/qemu-ifdown scripts:
chmod +x/etc/qemu-ifupchmod +x/etc/qemu-ifdown
- Finally, you need to restart your computer for the new/etc/network/interfaces configuration file to take effect.
To run the test:
./qemu-system-arm . -net nic,vlan=0 -net tap,vlan=0, Ifname=tap0
If the following information appears:
Warning:could not configure/dev/net/'tap'
then manually execute the following command first:
/etc/qemu-ifup tap0
Note: You cannot use sudo to execute the previous command, and you will need to manually execute the previous command every time you start Ubuntu.
Configuring QEMU's network capabilities with QEMU simulation VEXPRESS-A9---