Can't ping to vagrant box

13

3

I'm trying to create a Vagrant base box following the 2 resources here:

Using Ubuntu 12.10 (with LAMP) as the OS, I have 1 problem. I couldn't ping the vagrant IP which is 10.0.2.15 although I could SSH via vagrant ssh.

How do I set it up such that I could access the web server from my host?

VirtualBox: 4.2.10
Guest OS: Ubuntu12.10
Host: OSX 10.8.3

resting

Posted 2013-03-23T08:59:43.907

Reputation: 611

Does http://superuser.com/a/705625/103551 contain the solution? If so, please accept it as the answer.

– Cees Timmerman – 2016-03-09T12:36:45.773

I had a similar problem, and I think it was weird staleness of IPs. After changing the IPs (which were arbitrary anyway), it started working again: https://superuser.com/a/1214376/74576

– Ryan – 2017-11-03T14:45:59.887

Answers

15

You can't just access a Vagrant box with its IP address from the host system. Vagrant's networking is meant to define an abstraction layer that works across multiple providers.

The easiest way to access services on your Vagrant box is to configure port forwarding. In your Vagrantfile, see the section Vagrant.configure and set values for config.vm.network :forwarded_port. For example, the following configuration forwards port 4567 on your local system to port 80 on the Vagrant box:

Vagrant.configure("2") do |config|
  config.vm.box = "precise32"
  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.network :forwarded_port, host: 4567, guest: 80
end

After making this change, run vagrant reload to apply the changes. After applying the change, you should be able to point your web browser to http://127.0.0.1:4567 to have the Vagrant Apache instance serve a web page. You can read a bit more about this in the Vagrant V2 documentation or on the Vagrant networking page.

Steve HHH

Posted 2013-03-23T08:59:43.907

Reputation: 5 590

2

I had to manually start the network on my host-system as ip addr showed it was DOWN:

sudo ip link set up dev vboxnet0

codewandler

Posted 2013-03-23T08:59:43.907

Reputation: 121

1

I had a similar issue, just with the private network setup and the static IP. The IP address I used for months (192.168.10.10) was suddenly unreachable, although I was able to access the virtual machine with vagrant ssh.

Changing the static IP to 192.168.10.192 solved the problem. The solution here was to change the IP so it doesn't collide with any other machine on the same network.

Here you can find the following notes:

It is up to the users to make sure that the static IP doesn't collide with any other machines on the same network.

While you can choose any IP you'd like, you should use an IP from the reserved private address space. These IPs are guaranteed to never be publicly routable, and most routers actually block traffic from going to them from the outside world.

For some operating systems, additional configuration options for the static IP address are available such as setting the default gateway or MTU.

Warning! Do not choose an IP that overlaps with any other IP space on your system. This can cause the network to not be reachable.

In Vagrantfile you can configure the static IP like this

Vagrant.configure("2") do |config|
  config.vm.network "private_network", ip: "192.168.10.192"
end

Or, in case you're using Homestead like I do, just update your Homestead.yaml configuration file:

---
ip: "192.168.10.192"
# the rest of the configuration...

And a quick note for the end - my issue possibly wasn't identical as the one here, but since I stumbled upon this question, probably other users will too.

Nikola Prokopić

Posted 2013-03-23T08:59:43.907

Reputation: 111

1

I found the solution here: http://docs.vagrantup.com/v2/getting-started/networking.html

I just needed to set up port forwarding.

resting

Posted 2013-03-23T08:59:43.907

Reputation: 611

2link only answers = bad, what happens when the link dies? – Andrew – 2016-05-17T18:35:35.183

4While this obviously answers the question, it would be preferred if you would summarize the contents of that link, and post the link as just a reference; that way, if the link goes down, this answer still has merit – Canadian Luke – 2013-11-28T16:48:36.733

0

What worked for me was enabling bridged networking in the Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.network "public_network"
end

Richard Nienaber

Posted 2013-03-23T08:59:43.907

Reputation: 131

0

I think this source can help : http://docs-v1.vagrantup.com/v1/docs/host_only_networking.html

good luck ;)

user289721

Posted 2013-03-23T08:59:43.907

Reputation: 1

1Please describe procedure here because links often end up being dead. – tumchaaditya – 2014-01-13T22:38:45.820

Please, do not provide answers that are just links. Here's some reasons: http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers http://meta.stackexchange.com/questions/7515/why-is-linking-bad

– That Brazilian Guy – 2014-01-13T22:39:03.270

-1

on Ubuntu 12 host/Ubuntu 12 guest the following worked for me with discourse

I add host IP determined by vagrant and guest IP determined by Vagrant to firewall exceptions

niccolox

Posted 2013-03-23T08:59:43.907

Reputation: 1

1

Please give details and not just one-line answers. http://superuser.com/help/how-to-answer

– Kevin Panko – 2014-02-10T22:30:36.790