Prerequisites:
- Install qemu via MacPorts.
- Install tuntap via brew.
Steps:
- Add a bridge with some Thunderbolt interface via System Preferences -> Network -> Manage Virtual interfaces:
- Turn On Internet Sharing with the created bridge via System Preferences -> Sharing:
Now you are ready to start qemu, just add -nic tap
option
for the NAT-interface. After the VM is started, tapN interface
will appear in the host. Add it to the bridge:
sudo ifconfig bridge0 addm tapN
For the convenience, you can create the following two scripts which qemu will run by default for tap network interfaces for each VM. The scripts add and remove the tapN-interface to/from the bridge. Otherwise, you will have to do this manually for each VM. Here are the scripts:
$ cat /opt/local/etc/qemu-ifup
#!/bin/sh
#
TAPDEV="$1"
BRIDGEDEV="bridge0"
#
ifconfig $BRIDGEDEV addm $TAPDEV
$ cat /opt/local/etc/qemu-ifdown
#!/bin/sh
#
TAPDEV="$1"
BRIDGEDEV="bridge0"
#
ifconfig $BRIDGEDEV deletem $TAPDEV
The scripts should be placed as shown above, at /opt/local/etc/
.
Tested on macOS Mojave 10.14.6 and qemu-5.2.0_0+cocoa+target_arm+target_i386+target_x86_64+usb, qemu-6.1.0_0+cocoa+target_arm+target_i386+target_x86_64+usb with glib2-2.58.3_1+x11, libffi-3.3_1 ports.
UPD: it doesn't work with the latest (20 Oct 2021) version
of glib2-2.62.6_2+x11. Looks like it stopped working since 11 Aug
2021, when glib2 was updated from 2.58 to 2.62 version in ports.
tcpdump -i bridge0
shows DHCP requests and the replies, but
tcpdump -i tap0
shows only DHCP requests without replies.
Filed https://trac.macports.org/ticket/63650 about it.
Thanks for documenting this @andriytk
Could you add the full qemu command you are running?