Arnaud
Arnaud

Reputation: 604

QEMU on macOS big sur: connect to guest from the host without port forwarding

I'm having a hard time finding a solution to access my Linux guest system running on QEMU from my macOS Big Sur host.

The only solution I've found that works is port forwarding (using e.g. -net user,hostfwd=tcp::2200-:22 for SSH). This works, but is not convenient since I need to forward all the ports I need to use, and I would like to be able to use scripts, applications, etc. without having to tweak the ports everywhere.

So having an IP to connect from the host to the guest would be best, but surprisingly I couldn't find an easy to do so.

Upvotes: 3

Views: 4829

Answers (3)

Max-i-mil
Max-i-mil

Reputation: 61

I was trying to achieve a similar setup and the approved answer was a big help.

By using QEMU 7.1+ you can make use of Apple’s VMNET framework for networking with VMs without port forwarding.

QEMU makes use of this with -netdev vmnet-shared / vmnet-bridged / vmnet-host More detail can be found on the man page man qemu-system-aarch64

I have a short summary here: https://gist.github.com/max-i-mil/f44e8e6f2416d88055fc2d0f36c6173b

Upvotes: 6

Zheng Te
Zheng Te

Reputation: 427

socket_vmnet might solve your problem

https://github.com/lima-vm/socket_vmnet

As Lima claims

The guest IP is assigned by the DHCP server provided by macOS. The guest is accessible to the internet, and the guest IP is accessible from the host.

Upvotes: 0

Arnaud
Arnaud

Reputation: 604

The only articles I found online related to this seem to be valid only for older versions of macOS.

Looks like newer versions of macOS have a new mechanism for this, called vmnet.

And a patch for QEMU was implemented recently: https://gitlab.com/qemu-project/qemu/-/issues/465

With this patch, using -nic vmnet-host makes the guest accessible from the host (on an interface called bridge100).

At the moment, the latest stable release of QEMU (7.0.0) doesn't include this patch, but it's possible with brew to build the latest HEAD from git, which includes this change (but can't be considered stable!), using brew install qemu --HEAD.

Afterwards, make sure to use the correct qemu binary, by updating your PATH env variable or executing the binary with full path directly. Should be something like this: /usr/local/Cellar/qemu/HEAD-7077fcb/bin/

Upvotes: 1

Related Questions