QEMU Virtual Networks using SLIRP with Multicast

M Castelino
2 min readApr 11, 2019


Typically root privileges and host network configuration are needed to setup virtual machine networking when both inter VM networks and external network access is required. This involves setting up network interface and routing rules or using network name spaces.

Here we talk about using a combination of SLIRP and Multicast to setup Virtual Networking. In this setup VM’s can communicate with the outside world and between each other other without any setup on the host.

This uses two features available in qemu

  • User Mode Networking stack — SLIRP
  • Socket networking backend allows you to create a network of guests that can see each other

This allows us to have

  • SLIRP to communicate to the outside world
  • multicast to communicate between the VMs
  • And it uses the multicast to allow the host to communicate with the guests

Virtual Machine launch

qemu-system-x86_64 \
-machine pc,accel=kvm,kernel_irqchip \
-enable-kvm \
-bios OVMF.fd \
-smp sockets=1,cpus=4,cores=2 -cpu host \
-m 1024 \
-vga none -nographic \
-drive file="$IMAGE",if=virtio,aio=threads,format=raw \
-netdev user,id=mynet0,hostfwd=tcp::${VMN}0022-:22,hostfwd=tcp::${VMN}2375-:2375 \
-device virtio-net-pci,netdev=mynet0 \
-netdev socket,id=vlan,mcast= \
-device virtio-net-pci,netdev=vlan \

You can add any number of VM’s to this socket network, choosing a different value for VMN

Connecting to this network from the host

You can use socat to create a tap interface on the host with an IP in the same subnet as you want to VLAN to be on and

sudo socat UDP4-DATAGRAM:,sourceport=1234,reuseaddr,ip-add-membership= TUN:,tun-type=tap,iff-no-pi,iff-up,tun-name=vmvlan0

This will create a tap interface vmvlan0 on the host with IP:

We can run a DHCP server on this tap interface to allow for seamless configuration of the VLAN driven by the host

DHCP based VLAN configuration

To assign IP addresss to these VM’s from the host you can use dnsmasq serving DHCP on the vmvlan0 interface.

sudo -E dnsmasq --conf-file=dnsmasq.conf --leasefile-ro