Skip to content

Qemu tap bridge networking on macos osx

mvgijssel edited this page Mar 7, 2020 · 1 revision

Qemu tap bridge networking on macos/osx

Configure bridge interface

Install tuntap using homebrew

brew cask install tuntap

Create the bridge interface

sudo ifconfig bridge1 create

Assign ip address to bridge

sudo ifconfig bridge1 192.168.100.1/24

Enable packet forwarding

sudo sysctl -w net.inet.ip.forwarding=1

Create pfctl_nat_config configuration file

nat on en0 from bridge1:network to any -> (en0)

Apply pfctl rules

sudo pfctl -F all # This flushes all active rules
sudo pfctl -f pfctl_nat_config -e # Enable pf with the config

Enable the bridge

sudo ifconfig bridge1 up

Configure dnsmasq

Install dnsmasq

brew install dnsmasq

Start dnsmasq on the bridge

sudo dnsmasq -d --interface=bridge1 --dhcp-range=192.168.100.10,192.168.100.50,1h --log-queries

Configure qemu

Create qemu-ifup.sh for qemu

#!/bin/bash

sudo ifconfig bridge1 addm $1

Create qemu-ifdown.sh for qemu

#!/bin/bash

sudo ifconfig bridge1 deletem $1

Additional arguments for qemu

 -netdev tap,id=mynet0,script=./qemu-ifup.sh,downscript=./qemu-ifdown.sh \
 -device virtio-net,netdev=mynet0 \

(Optional) create /etc/sudoers.d/ifconfig_sudoers file to not have to type sudo password for ifconfig

%staff ALL = NOPASSWD: /sbin/ifconfig

Resources