There are two parts to networking within QEMU:
The virtual network device that is provided to the guest (e.g. a PCI network card).The network backend that interacts with the emulated NIC (e.g. puts packets onto the host's network).Example: User mode network
User mode networking allows the guest to connect back to the outside world through TCP, UDP etc. ICMP Ping is not allowed. Also connections from host to guest are not allowed unless using port forwarding.
$ qemu-system-i386 -cdrom Core-current.iso -boot d -netdev user,id=mynet0,hostfwd=tcp::8080-:80 -device e1000,netdev=mynet0-netdev user,id=mynet0,hostfwd=tcp::8080-:80
Create the user mode network backend having id mynet0. Redirect incoming tcp connections on host port 8080 to guest port 80. The syntax is hostfwd=[tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport
-device e1000,netdev=mynet0
Create a NIC (model e1000) and connect to mynet0 backend created by the previous parameter
Example: Tap network
TAP network overcomes all of the limitations of user mode networking, but requires a tap to be setup before running qemu. Also qemu must be run with root privileges.
$ sudo qemu-system-i386 -cdrom Core-current.iso -boot d -netdev tap,id=mynet0,ifname=tap0,script=no,downscript=no -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01-netdev tap,id=mynet0,ifname=tap0,script=no,downscript=no
Create a tap network backend with id mynet0. This will connect to a tap interface tap0 which must be already setup. Do not use any network configuration scripts.
-device e1000,netdev=mynet0,mac=52:55:00:d1:55:01
Create a NIC (model e1000) and connect to mynet0 backend created by the previous parameter. Also specify a mac address for the NIC.
Create a bridge
brctl addbr br0Clear IP of eth0
ip addr flush dev eth0Add eth0 to bridge
brctl addif br0 eth0Create tap interface
tunctl -t tap0 -u `whoami`Add tap0 to bridge
brctl addif br0 tap0Make sure everything is up
ifconfig eth0 up ifconfig tap0 up ifconfig br0 upCheck if properly bridged
brctl showAssign ip to br0
dhclient -v br0Remove tap interface tap0 from bridge br0
brctl delif br0 tap0Delete tap0
tunctl -d tap0Remove eth0 from bridge
brctl delif br0 eth0Bring bridge down
ifconfig br0 downRemove bridge
brctl delbr br0Bring eth0 up
ifconfig eth0 upCheck if an IP is assigned to eth0, if not request one
dhclient -v eth0Release IP
dhclient -v -r <interface>Request IP
dhclient -v <interface>