Vagrant: ssh timeouts on `vagrant up` if private_network is defined

Created on 18 Mar 2018  ยท  8Comments  ยท  Source: hashicorp/vagrant

Vagrant version: 2.0.2
Host operating system: macOS High Sierra 10.13.3
Guest operating system: Alpine Linux x86_64 4.9.73

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "alpine/alpine64"
  config.vm.network :private_network, type: :dhcp
  config.vm.provider "virtualbox" do |vb|
    vb.linked_clone = true
  end

  ## configuration for agent machine
  config.vm.define "agent" do |agent|
    agent.vm.provision "shell" do |shell|
      shell.inline = "echo 'Starting agent machine...'"
    end
  end

  ## configuration for monitor machine
  config.vm.define "monitor" do |monitor|
    monitor.vm.provision "shell" do |shell|
      shell.inline = "echo 'Starting monitor machine...'"
    end
  end

end

Debug output

Expected behavior

Two machines starts in same private network. Vagrant can ssh into both machines during vagrant up execution.

Actual behavior

When starting first machine the ssh connection timeouts. However, if you comment line 6 in Vagrant file, the line with config.vm.network :private_network, type: :dhcp, machines starts normally and ssh works.
It seems that enabling private_network makes ssh fail during vagrant up.

Steps to reproduce

  1. vagrant up
guesalpine needs-repro networking

Most helpful comment

My code looks like:

`Vagrant.configure("2") do |config|

config.vm.box = 'maier/alpine-3.6-x86_64'
config.vm.provider :virtualbox do |vb|
    vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
end

 config.vm.define 'web' do |web|
    web.vm.network 'private_network', ip: '10.0.0.11', auto_config: false
    ENV['LC_ALL']='en_US.UTF-8'
end

config.vm.define 'db' do |db|
    db.vm.network 'private_network', ip: '10.0.0.12', auto_config: false
    ENV['LC_ALL']='en_US.UTF-8'
end

end`

How I resolve connection problem:

  • in web machine in /etc/network/interfaces I add manually my IP:
    auto eth1
    iface eth1 inet static
    address 10.0.0.11
    netmask 255.255.255.0

  • in db machine in /etc/network/interfaces I add:
    auto eth1
    iface eth1 inet static
    address 10.0.0.12
    netmask 255.255.255.0

After it, I restarted my network interfaces with /etc/init.d/networking restart and finally works.

All 8 comments

Encountering this issue on my own machine, using the same box as above and an even simpler config using fixed IP. It could possibly be an issue with the alpine box. Debug data is essentially the same. I've tried playing with configuring SSH in a few different ways and get a timeout each time.

Vagrant.configure("2") do |config|
  config.vm.box = "alpine/alpine64"
  config.vm.network "forwarded_port", guest: 80, host: 8008
  config.vm.network "private_network", ip: "192.168.10.12"
  config.vm.synced_folder ".", "/var/www/localhost/htdocs"

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "1024"
  end
end

Vagrant 2.0.3
Host OS : Microsoft Windows NT 10.0.16299.0
Guest OS : Alpine Linux 3.7.0

Edit: After some further testing, I can confirm that the issue is also present on "generic/alpine37" and "generic/alpine36" images, and with some fiddling I managed to get "maier/alpine-3.6-x86_64" to show the message

Vagrant attempted to execute the capability 'configure_networks'
on the detect guest OS 'linux', 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.

And this cause of the issue seems borne out by adding config.vm.network "private_network", ip: "192.168.10.12", auto_config: false to the config, and it magically boots.

I've tried @rwattogl suggested by adding auto_config: false but did not worked.

What I've tried then was:

  1. check If I can ssh with regular ssh command (not vagrant ssh) - I couldn't. Despite ssh told me that connection was reset by peer, looking into server logs - with vb.gui = true - told me that no connection is coming to the virtual machine.
  2. I've checked ifconfig - only eth0 was up (NAT interface), eth1 was down (host-only) - it shouldn't be a problem as sshd is supposed to bind to all interfaces (0.0.0.0:22) and port forwaring in virtualbox is set to adapter 1, which is eth0.
  3. for curiosity I've destroyed the box and started again. When ssh was trying to connect during vagrant up, I've logged in via VirtualBox gui and edited /etc/network/interfaces with entry for eth1 and made up that interface - then checked vagrant process and discovered that ssh connected!
    However after a while I get error message from vagrant:
Vagrant attempted to execute the capability 'configure_networks'
on the detect guest OS 'linux', 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.

I don't know what to do further as I'm not a maintainer of the base image used. It seems that alpine is not fully compatibile with vagrant.
Adding the auto_config: false makes finally alpine work seamlessly.

So, it seems that if I want to run a few machines in one private netwrork, then I need maually edit /etc/network/interfaces on each machine to alllow vagrant ssh into them and strat provisioning....

BTW, vagrant halt also is not working also on this system - the regular shutdown -P now command is replaced with busybox poweroff.

Installing https://github.com/maier/vagrant-alpine into vagrant also seemed to fix a fair number of my problems.

I'm using box generic/alpine38.

I would like to confirm that adding auto_config: false to the config.vm.network line fixed my networking.
Ex. config.vm.network "private_network", type: "dhcp", auto_config: false

But my NFS is still broken

No guest IP was given to the Vagrant core NFS helper. This is an
internal error that should be reported as a bug.

Perhaps this should be considered a separate issue.

Update, I would like to add that https://github.com/maier/vagrant-alpine doesn't remedy this.

NFS isn't setup, by default, with the generic boxes. Not sure it should be, it has security implications. Personally, I use the vagrant upload command to push files into the guests.

My code looks like:

`Vagrant.configure("2") do |config|

config.vm.box = 'maier/alpine-3.6-x86_64'
config.vm.provider :virtualbox do |vb|
    vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
end

 config.vm.define 'web' do |web|
    web.vm.network 'private_network', ip: '10.0.0.11', auto_config: false
    ENV['LC_ALL']='en_US.UTF-8'
end

config.vm.define 'db' do |db|
    db.vm.network 'private_network', ip: '10.0.0.12', auto_config: false
    ENV['LC_ALL']='en_US.UTF-8'
end

end`

How I resolve connection problem:

  • in web machine in /etc/network/interfaces I add manually my IP:
    auto eth1
    iface eth1 inet static
    address 10.0.0.11
    netmask 255.255.255.0

  • in db machine in /etc/network/interfaces I add:
    auto eth1
    iface eth1 inet static
    address 10.0.0.12
    netmask 255.255.255.0

After it, I restarted my network interfaces with /etc/init.d/networking restart and finally works.

Hi there,

It looks like this has been resolved within a previously shipped version of Vagrant so I am now closing this issue. If the original issue was not fully resolved, please reopen this issue or create a new one.

Cheers!

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

Related issues

jsirex picture jsirex  ยท  3Comments

jazzfog picture jazzfog  ยท  3Comments

hesco picture hesco  ยท  3Comments

janw-me picture janw-me  ยท  3Comments

DreadPirateShawn picture DreadPirateShawn  ยท  3Comments