Vagrant: Automatically setup host-only network for NFS on Vagrant installation

Created on 17 Oct 2017  ยท  7Comments  ยท  Source: hashicorp/vagrant

I'm trying to use NFS for synced folders with Vagrant, but when I vagrant up, I get:

NFS requires a host-only network to be created.
Please add a host-only network to the machine (with either DHCP or a
static IP) for NFS to work.

I'm not really sure what the exact steps required for this would be. If possible, could Vagrant automatically setup host-only network on installation?

Vagrant version

2.0.0

Host operating system

macOS Sierra

Guest operating system

FreeBSD

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "uchida/freebsd"
  config.vm.synced_folder ".", "/vagrant", type: "nfs"
end
enhancement providevirtualbox

Most helpful comment

Hi @mcandre - due to the limitations wth VirtualBox's built in networking, you must create a private network for NFS. More information about that can be found in the pre-req section of the synced_folder docs: https://www.vagrantup.com/docs/synced-folders/nfs.html#prerequisites

For more information about setting up a private network, you can check out the docs here: https://www.vagrantup.com/docs/networking/private_network.html#dhcp

However it should be as easy as dropping in this line for your config:

config.vm.network "private_network", type: "dhcp"

Thanks!

All 7 comments

Hi @mcandre - due to the limitations wth VirtualBox's built in networking, you must create a private network for NFS. More information about that can be found in the pre-req section of the synced_folder docs: https://www.vagrantup.com/docs/synced-folders/nfs.html#prerequisites

For more information about setting up a private network, you can check out the docs here: https://www.vagrantup.com/docs/networking/private_network.html#dhcp

However it should be as easy as dropping in this line for your config:

config.vm.network "private_network", type: "dhcp"

Thanks!

A few notes:

  • Yes, NFS would be ideal as a more efficient method than rsync.
  • /vagrant should be synced by the base box automatically, not by downstream users.
  • NFS unfortunately does not work for many BSD boxes. In particular, b00ga/dragonfly50 appears to lack the vagrant integration configure_networks, preventing NFS from working.

Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "b00ga/dragonfly50"
  config.vm.box_version = "0.1.1"

  config.vm.network "private_network", type: "dhcp"
  config.vm.synced_folder ".", "/vagrant", type: "nfs"
end

Trace:

$ vagrant up
...
Vagrant attempted to execute the capability 'configure_networks'
on the detect guest OS 'dragonflybsd', but the guest doesn't
support that capability. This capability is required for your
configuration of Vagrant. Please either reconfigure Vagrant to
avoid this capability or fix the issue by creating the capability.

As a workaround, I am manually configuring my box to use rsync. Would be nice to get either NFS or rsync /vagrant working in the base box by default. For now, I'm using this configuration to get things up and running.

Vagrant.configure("2") do |config|
  config.vm.box = "b00ga/dragonfly50"
  config.vm.box_version = "0.1.1"

  config.vm.synced_folder ".", "/vagrant", type: "rsync"
end

Again, thank you for putting in all so much effort to help DragonFly BSD users work with Vagrant, it's much appreciated!

Hey @mcandre - if I remember correctly, that folder /vagrant should be syncing by default. Have you seen what happens if you leave it out of your config? The only downside is I think it uses the virtualbox built in shared folders protocol by default, but maybe that's alright? Unless you are specifically looking to use rsync or nfs, then you'd want to define that config option like you have above.

/vagrant should be syncing by default

I agree, though BSD boxes tend to screw up how shared folders are managed. When I omit config.vm.synced_folder ".", "/vagrant", type: "rsync", then BSD guests tend to exit vagrant up with a complaint before the vagrant provision phase.

Odd, when I remove explicit config.vm.guest setting from my dragonflybsd Vagrantfile, my box skips over the rsync_install capability step, then of course dies on rsync not found. Browsing through the dragonflybsd guest plugin code, everything looks okay, correctly extends the freebsd guest plugin, which specifies the right command for installing rsync in freebsd and dragonflybsd: sudo pkg install -y rsync. I have no idea why this step is being skipped for the box.

Update

I tinkered some more and discovered that the dragonflybsd guest plugin is skipping the rsync_install step. Tracking that bug in https://github.com/hashicorp/vagrant/issues/9335

This sounds like a reasonable idea, but this has low chance of being a priority for us anytime soon, so we'd rather close this issue than have it stagnate into the foreseeable future. The best way to get this implemented would be to submit a PR. If you do so, we'd welcome this work. If you want to discuss how to go about doing this, I'd be happy to help with that.

Again, thank you for suggesting this and it is a reasonable idea. But, since this is a feature request, it requires some work to add it to the project and we don't plan on doing that soon. But as this is also an open source project we welcome contributions. Thanks!

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings