When QEMU is started, the tap virtual network card and qemutap virtual network card are inserted.
1. Use the brctl command to create a virtual bridge br0
Brctl addbr br0
Ifconfig br0 up // the preceding two commands are executed separately, leading to network disconnection.
2. Bind the virtual bridge br0 to the physical Nic eth0.
Brctl addif br0 eth0
Ifconfig eth0 0.0.0.0 // The net bridge is similar to a switch. In this case, you can think that eth0 is only a port on the switch. You can think that all data packets are imported from eth0, but the net bridge decides the packet flow, therefore, you only need to mark the IP address of the bridge.
3. Use DHCP to assign IP addresses to br0
Dhclient br0
4. Create a virtual TAP Nic
Tunctl-B-t tap0 // ubuntu tunctl installation command: sudo apt-get install uml-utilities
Ifconfig tap0 up
Brctl addif br0 tap0
5. Create a VM and associate the NIC
Sudo qemu-system-x86_64 ubuntu-15.04-snappy-amd64-generic.img-m 1024-net nic-net tap, ifname = tap4, script = no, downscript = no-enable-kvm