The blog

Making stupid bridged networking work on wifi (because usermode networking is not good enough)

This is how I setup the network when I run a VM on a laptop.

Create a bridge on networkmanager:

$ nmcli connection add type bridge ifname br0 stp no \
  ipv4.addresses ipv4.method manual br0

(it will be DOWN but already be visible in ip link)

Set up a dhcp server for our vms using dnsmasq

# systemctl enable --now dnsmasq

Enable forwarding

In /etc/sysctl.conf or /etc/sysctl.d/99-sysctl.conf:

net.ipv4.ip_forward = 1
# sysctl -p /etc/sysctl.conf

Tell iptables to please forward

iptables -A FORWARD -i br0 -o wlp2s0 -j ACCEPT
iptables -t nat -A POSTROUTING -o wlp2s0 -j MASQUERADE
iptables -A FORWARD -i wlp2s0 -o br0 -m state --state RELATED,ESTABLISHED -j ACCEPT

(This does not persist across reboots)

Configure the qemu bridge helper

write allow br0 in /etc/qemu/bridge.conf

let qemu-bridge-helper do its thing:

$ sudo chmod u+s /usr/lib/qemu/qemu-bridge-helper

And finally

$ qemu-system-x86_64 -cpu host -enable-kvm -m 2048 \
    -nic bridge,br=br0,mac=52:54:28:86:30:65,model=virtio \
    -device virtio-scsi-pci,id=scsi \
    -drive if=none,id=vd0,file=vm.qcow2.img \
    -device scsi-hd,drive=vd0

(or whatever else, set the MAC to something unique - the only important part here is the -nic)


Got any comments? Send me an email: