For background, qemu/kvm support a few ways to provide network to guests. The default is user networking, which requires no privileges, but is slow and based on ancient SLIRP code. The other common option is tap networking, which is fast, but complicated to set up. Turns out, with networkd and qemu bridge helper, tap is easy to set up.
$ for file in /etc/systemd/network/*; do echo $file; cat $file; done /etc/systemd/network/eth.network [Match] Name=eth1 [Network] Bridge=br0 /etc/systemd/network/kvm.netdev [NetDev] Name=br0 Kind=bridge /etc/systemd/network/kvm.network [Match] Name=br0 [Network] DHCP=yesDiverging from Joachims simple example, we replaced "DHCP=yes" with "Bridge=br0". Then we proceed to define the bridge (in the kvm.netdev) and give it an ip via dhcp in kvm.network. From the kvm side, if you haven't used the bridge helper before, you need to give the helper permissions (setuid root or cap_net_admin) to create a tap device to attach on the bridge. The helper needs an configuration file to tell what bridge it may meddle with.
# cat > /etc/qemu/bridge.conf <<__END__ allow br0 __END__ # setcap cap_net_admin=ep /usr/lib/qemu/qemu-bridge-helperNow we can start kvm with bridge networking as easily as with user networking:
$ kvm -m 2048 -drive file=jessie.img,if=virtio -net bridge -net nic,model=virtio -serial stdioThe manpages systemd.network(5) and systemd.netdev(5) do a great job explaining the files. Qemu/kvm networking docs are unfortunately not as detailed.
No comments:
Post a Comment