AirPlay across broadcast domains

AirPlay is great and "just works" if all your devices are on the same network. But if your device and TV are on separate broadcast domains, for example different VLANs, they will not be able to discover each other. Luckily the solution is simple.

Find somewhere to run Linux (in my case a Raspberry Pi), plug it on a hybrid switch port, and create a new interface for each VLAN you would like to "bridge" the multicast domain.

$ apt install -y vlan
$ cat /etc/netplan/50-vlans.yaml
network:
  version: 2
  ethernets:
    eth0:
      optional: true
  vlans:
    vlan10:
      id: 10
      link: eth0
      dhcp4: true
      macaddress: aa:bb:cc:dd:ee:01
    vlan20:
      id: 20
      link: eth0
      dhcp4: true
      macaddress: aa:bb:cc:dd:ee:02
$ netplan generate
$ netplan apply

Next we need to install Avahi and enable its mDNS reflector.

$ apt install -y avahi-daemon
$ sed -i 's/#enable-reflector=no/enable-reflector=yes/' /etc/avahi/avahi-daemon.conf
$ sed -i 's/#allow-interfaces=eth1/allow-interfaces=vlan10,vlan20/' /etc/avahi/avahi-daemon.conf
$ systemctl restart avahi-daemon

That's it! You should see mDNS traffic on the Avahi host with tcpdump -n host 224.0.0.251 and port 5353 between your MacOS/iOS and AirPlay devices.