How to setup private network
Is it possible to setup private network through Vagrantfile?
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
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 asvmnet-shared, but providing network unique id (uuid) can makevmnet-hostinterfaces isolated from each other and also disables DHCP.vmnet-bridged: bridges the guest with a physical network interface.
- the
vmnet-sharedandvmnet-hostlook 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.
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 , @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.
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.