来自https://gist.github.com/extremecoders-re/e8fd8a67a515fee0c873dcafc81d811c
Setting up Qemu with a tap interface
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.
Setup
-
Create a bridge
brctl addbr br0 -
Clear IP of
eth0ip addr flush dev eth0 -
Add
eth0to bridgebrctl addif br0 eth0 -
Create tap interface
tunctl -t tap0 -u `whoami` -
Add
tap0to bridgebrctl addif br0 tap0 -
Make sure everything is up
ifconfig eth0 up ifconfig tap0 up ifconfig br0 up -
Check if properly bridged
brctl show -
Assign ip to
br0dhclient -v br0
Cleanup
-
Remove tap interface
tap0from bridgebr0brctl delif br0 tap0 -
Delete
tap0tunctl -d tap0 -
Remove eth0 from bridge
brctl delif br0 eth0 -
Bring bridge down
ifconfig br0 down -
Remove bridge
brctl delbr br0 -
Bring
eth0upifconfig eth0 up -
Check if an IP is assigned to
eth0, if not request onedhclient -v eth0
dhclient - Auto configuration using a DHCP server
-
Release IP
dhclient -v -r <interface> -
Request IP
dhclient -v <interface>
Qemu与Tap接口的网络设置
博客介绍了在QEMU中设置网络的相关内容,包括用户模式网络和Tap网络。用户模式网络有一定限制,而Tap网络可克服这些限制,但需提前设置tap且以root权限运行qemu。还给出了设置和清理的步骤,以及使用DHCP服务器自动配置的方法。
6935

被折叠的 条评论
为什么被折叠?



