VirtualBox guest not getting ip address assigned by Vagrantfile
Asked Answered
M

3

7

Upon vagrant up, the guest box is getting assigned the wrong IP address and causing the following error:

...
...
SSH address: 127.0.0.1:2222
serverbox: SSH username: vagrant
serverbox: SSH auth method: private key
serverbox: Warning: Connection timeout. Retrying...
serverbox: Warning: Connection timeout. Retrying...
serverbox: Warning: Connection timeout. Retrying...
...

I do work at home and at the office so must always reconfigure the ip address assignment in Vagrantfile depending on where I am at because the subnets are different. (192.168.x.x versus 10.80.x.x)

This has worked fine until just yesterday. I have no idea what is causing the issues as I haven't made any adjustments.

Vagrantfile:

Vagrant.configure("2") do |config|                                                                                                                       
  config.vm.provider "virtualbox" do |vb|                                                                                                                
    vb.customize ["modifyvm", :id, "--memory", "512"]                                                                                                    
  end                                                                                                                                                    
  config.vm.network "public_network", ip: '10.80.2.144'
  #config.vm.network "public_netowrk", ip: '192.168.1.144'                                                                                        
end

...

The Vagrantfile should put my guestbox on the 10.80.x.x address but netstat shows that my box is still going up on the 192.168.x.x address. This means I am unable to work with the guestbox since it is going to an out of bounds subnet.

I've done halt and up again as well as completely rebooting my cpu and checking to make sure virtualization is on in BIOS.

I've looked here and tried this method to no avail.

I also tried vb.gui = true but my machine is running headless. Virtualbox's Preview logging screen might provide some useful information but it is so small I can't make anything out of it. If someone has any advice on how to make that larger that could probably help a lot.

UPDATE:

So my solution is an undesired solution but my workday has been torpedoed and need to move forward so I just destroyed my box and re up'ed.

Apparently, my keys became insecure. Not sure how that happened but the new box replaced my keys.

Magenmagena answered 8/1, 2015 at 19:19 Comment(2)
I guess if you downvote, you should at least leave a response as to why if it isn't clear.Magenmagena
The situation could be because of VirtualBox failed to redirect ports, despite saying '==> default: Forwarding ports... default: 22 => 2222 (adapter 1)' You may have a look at full description in my question here link. I still have no idea how to fix redirection fail( Please drop a note in my post, if and how you succeed!Guerra
D
7

my suggestion for your issue.

Run vagrant reload and vagrant provision on that instance after you changed IP.

If not get your problem fixed, try the second one:

change public_network to private_network

config.vm.network "private_network", ip: '10.80.2.144'
#config.vm.network "private_network", ip: '192.168.1.144'  
Diastole answered 8/1, 2015 at 20:38 Comment(5)
Tried vagrant provision after vagrant up and got the following: Vagrant timed out while attempting to connect via SSH... I then tried to change to private_network but received the following: The specified host network collides with a non-hostonly network! This will cause your specified IP to be inaccessible....Magenmagena
if you get time out error with provision command, then it is some other problem.Diastole
On another box I destroyed and ran vagrant up on it and it worked but it did the same thing.. "Remote connection disconnect. Retrying.." It then proceeded to find the keys to be insecure and replaced them on box creation. I was able to ssh in and it worked. I don't want to do this to my other box but looks like the only option left at this point.Magenmagena
setting the vm.network IP address worked for me when I ran vagrant up and didn't have an IP address to navigate toVacuity
vagrant reload and provision worked for me. For some unkown reason it did not set up IP address the first time, but on the vagrant reload.Recessional
R
2

Just add this two lines in the Vagrantfile and vagrant reload

config.vm.network "forwarded_port", guest: 80, host: 8080,
  auto_correct: true

config.vm.network "private_network", ip: "192.168.100.1",
  auto_config: false

Hope problem will be solve.

Rifle answered 2/9, 2016 at 17:23 Comment(0)
S
0

NOTE
This answer is not the problem solution. It might be helpful while debugging problems when you can't ssh in into your vagrant box

I got the issue using:

  • Vagrant 1.8.1
  • VirtualBox 5.0.12r104815
  • Vagrantfile option config.vm.network "private_network", ip: "10.50.50.3"

The following steps helped me to resolve my issue:

  • enabled the GUI in the Vagrantfile by adding vb.gui = true
  • started the VM with vagrant up
  • used the VirtualBox terminal to login (user: vagrant, password: vagrant)
  • checked the interface IP in the devbox

    $ sudo ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
    10.0.2.15
    
  • checked the local VirtualBox interface (with ifconfig):

    vboxnet8  Link encap:Ethernet  HWaddr 0a:00:27:00:00:08  
              inet addr:10.50.50.1  Bcast:10.50.50.255  Mask:255.255.255.0
              inet6 addr: fe80::800:27ff:fe00:8/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:258 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:39147 (39.1 KB)
    

I saw that the VM's ip doesn't fit to the hosts vboxnet8 interface ip range.

I tried to reload the VM with vagrant reload but with no success. The only thing which helped me was reseting the VM with vagrant destroy -f, vagrant up (see additional comment below).


How this could happen? After booting the VM the first time, one of my provisioning scripts changed the /etc/ssh/sshd_config which was afterwards invalid. Then the script restarted ssh which caused the connection problem.

Vagrant started the VM but I couldn't ssh into it.

Then I must have changed the private_network ip which caused the weird situation.

At the end making the /etc/ssh/sshd_config valid again fixed my issue.

Senghor answered 8/1, 2016 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.