vagrant-qemu icon indicating copy to clipboard operation
vagrant-qemu copied to clipboard

How to setup private network

Open Agus-Wei opened this issue 2 years ago • 5 comments

Is it possible to setup private network through Vagrantfile?

Agus-Wei avatar Apr 28 '23 00:04 Agus-Wei

There's been a couple issues created on this topic. https://github.com/ppggff/vagrant-qemu/issues/33 https://github.com/ppggff/vagrant-qemu/issues/36

leifliddy avatar May 03 '23 02:05 leifliddy

I have done some research for this problem on MacOS:

  • qemu add a new type of network 'vmnet-host|vmnet-shared|vmnet-bridged' based on MacOS vmnet.framework
    • vmnet-shared: allows the guest to communicate with other guests in shared mode and also with external network (Internet) via NAT. Has (macOS-provided) DHCP server; subnet mask and IP range can be configured;
    • vmnet-host: allows the guest to communicate with other guests in host mode. By default has enabled DHCP as vmnet-shared, but providing network unique id (uuid) can make vmnet-host interfaces isolated from each other and also disables DHCP.
    • vmnet-bridged: bridges the guest with a physical network interface.
  • the vmnet-shared and vmnet-host look like a good match to the public and private of vagrant network

But there still have some problem:

  • it needs root to run the qemu command (https://gitlab.com/qemu-project/qemu/-/issues/1364)
  • it doesn't support port forward by itself (need to work with user network together, you have 2 interfaces)
    • some box doesn't support 2 interfaces very well, and it's hard to control the order of these interfaces
  • it's hard to use a pre-defined ip address

Also there is a third party program socket_vmnet from the lima project:

  • it's also based on the MacOS vmnet.framework (so it has the same advantages and disadvantages as above)
  • qemu connect to socket_vmnet to make the network works
  • it needs root to run, by you can run the qemu command without root

I prefer to use qemu directly, maybe use sudo to handle the root problem. I will try to make it work with vagrant's network config soon.

ppggff avatar May 08 '23 02:05 ppggff

Any examples on how can we run a qemu VM with (e.g.) vmnet-bridged? Because when I tried to add it on the following args:

    qe.net_device = 'virtio-net-pci'
    qe.extra_netdev_args = 'vmnet-bridged=on,ifname=en0'

I got the following error, which suggests the plugin is pre/appending various other arguments that are not compatible with the vmnet arguments:

Stderr: qemu-system-x86_64: -netdev user,id=net0,hostfwd=tcp::50022-:22,vmnet-bridged=on,ifname=en0: Invalid parameter 'vmnet-bridged'

andronat avatar Jan 25 '24 03:01 andronat

@andronat , @ppggff already said this plugin hasn't been adjusted to work with vmnet-* yet.

Like you, I would love to use these solutions, but it's not possible yet.

unixerius avatar Feb 02 '24 09:02 unixerius

With regards to your post of May 8th, I feel that you should wait for Qemu to build in the required support for non-privileged users.

They themselves have already identified that their biggest hurdle is that their software isn't flagged by Apple as being permitted to use the com.apple.vm.networking entitlement. The main reason for this is A) that they haven't requested it and B) that their brew install does a build from source code. source

That seems like something they as project should be able to work on. Until they've done so, I would not recommend that you build in a sudo workaround.

unixerius avatar Feb 02 '24 12:02 unixerius