0% found this document useful (0 votes)
105 views

Configure NAT-network For QEMU On macOS Mojave GitHub

The document describes how to configure NAT networking for QEMU virtual machines on macOS Mojave. It provides prerequisites and steps to add a bridge interface, enable internet sharing, and start QEMU VMs with tap network interfaces connected to the bridge for NAT access. Scripts are included to automatically add and remove tap interfaces from the bridge when VMs start and stop. The configuration is tested with specific QEMU and macOS versions.

Uploaded by

ronare6613
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views

Configure NAT-network For QEMU On macOS Mojave GitHub

The document describes how to configure NAT networking for QEMU virtual machines on macOS Mojave. It provides prerequisites and steps to add a bridge interface, enable internet sharing, and start QEMU VMs with tap network interfaces connected to the bridge for NAT access. Scripts are included to automatically add and remove tap interfaces from the bridge when VMs start and stop. The configuration is tested with specific QEMU and macOS versions.

Uploaded by

ronare6613
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

28/12/2021, 17:29 Configure NAT-network for QEMU on macOS Mojave · GitHub

Instantly share code, notes, and snippets.


andriytk/qemu-on-mac-nat.md
Last active 3 days ago
Star

Code Revisions
17 Stars
2

Configure NAT-network for QEMU on macOS Mojave


qemu-on-mac-nat.md

Configure NAT-network for QEMU on


macOS Mojave
Prerequisites:
1. Install qemu via MacPorts.
2. Install tuntap via brew.
Steps:
1. Add a bridge with some Thunderbolt interface via System Preferences ->
Network -> Manage Virtual interfaces:

https://gist.github.com/andriytk/bd3def8c30cbd474490280436c779027 1/5
28/12/2021, 17:29 Configure NAT-network for QEMU on macOS Mojave · GitHub

https://gist.github.com/andriytk/bd3def8c30cbd474490280436c779027 2/5
28/12/2021, 17:29 Configure NAT-network for QEMU on macOS Mojave · GitHub

2. 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

https://gist.github.com/andriytk/bd3def8c30cbd474490280436c779027 3/5
28/12/2021, 17:29 Configure NAT-network for QEMU on macOS Mojave · GitHub

$ 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.

fgenoese commented 3 days ago


Thanks for documenting this @andriytk
Could you add the full qemu command you are running?

andriytk commented 3 days ago


sudo qemu-system-x86_64 -accel hvf -m 4G -smp 4 -hda centos-disk1.vmdk -nographic -nic
tap

fgenoese commented 3 days ago • edited

Bummer! Thought there was more magic behind. Cannot seem to get this working for a Raspberry P.
Emulation boots but has no network connection.
error:
qemu-system-aarch64: warning: netdev #net088 has no peer

qemu-system-aarch64: warning: requested NIC (anonymous, model unspecified) was not


created (not supported by this machine?)

https://gist.github.com/andriytk/bd3def8c30cbd474490280436c779027 4/5
28/12/2021, 17:29 Configure NAT-network for QEMU on macOS Mojave · GitHub

using the following qemu command:


sudo qemu-system-aarch64

-m 1G \

-M raspi3b \

-smp 4 \

-usb \

-device usb-mouse \

-device usb-kbd \

-device 'usb-net,netdev=net0' \

-netdev 'user,id=net0,hostfwd=tcp::5022-:22' \

-drive "file=2020-08-20-raspios-buster-armhf-lite.img,index=0,format=raw" \

-dtb bcm2710-rpi-3-b-plus.dtb \

-kernel kernel8.img \

-append 'rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0


root=/dev/mmcblk0p2 rootdelay=1' \

-no-reboot \

-nographic \

-nic tap

https://gist.github.com/andriytk/bd3def8c30cbd474490280436c779027 5/5

You might also like