Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Monday, January 25, 2016

Unable to connect to Vagrant private network from host

Unable to connect to Vagrant private network from host


I have a vagrant virtual box up and running. So far I have been unable to connect to the web server. here is the start up:

[jesse@Athens VVV-1.1]$ vagrant up  Bringing machine 'default' up with 'virtualbox' provider...  ==> default: Clearing any previously set forwarded ports...  ==> default: Clearing any previously set network interfaces...  ==> default: Preparing network interfaces based on configuration...      default: Adapter 1: nat      default: Adapter 2: hostonly  ==> default: Forwarding ports...      default: 22 => 2222 (adapter 1)  ==> default: Running 'pre-boot' VM customizations...  ==> default: Booting VM...  ==> default: Waiting for machine to boot. This may take a few minutes...      default: SSH address: 127.0.0.1:2222      default: SSH username: vagrant      default: SSH auth method: private key      default: Warning: Connection timeout. Retrying...  ==> default: Machine booted and ready!  ==> default: Checking for guest additions in VM...      default: The guest additions on this VM do not match the installed version of      default: VirtualBox! In most cases this is fine, but in rare cases it can      default: prevent things such as shared folders from working properly. If you see      default: shared folder errors, please make sure the guest additions within the      default: virtual machine match the version of VirtualBox you have installed on      default: your host and reload your VM.      default:       default: Guest Additions Version: 4.2.0      default: VirtualBox Version: 4.3  ==> default: Setting hostname...  ==> default: Configuring and enabling network interfaces...  ==> default: Mounting shared folders...      default: /vagrant => /home/jesse/vagrant/vvvStable/VVV-1.1      default: /srv/www => /home/jesse/vagrant/vvvStable/VVV-1.1/www      default: /srv/config => /home/jesse/vagrant/vvvStable/VVV-1.1/config      default: /srv/database => /home/jesse/vagrant/vvvStable/VVV-1.1/database      default: /var/lib/mysql => /home/jesse/vagrant/vvvStable/VVV-1.1/database/data  ==> default: VM already provisioned. Run `vagrant provision` or use `--provision` to force it  ==> default: Checking for host entries  

on my host console, ip addr show yields:

4: vboxnet0:  mtu 1500 qdisc noop state DOWN group default qlen 1000                                             link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff                                                                           5: vboxnet1:  mtu 1500 qdisc noop state DOWN group default qlen 1000                                            link/ether 0a:00:27:00:00:01 brd ff:ff:ff:ff:ff:ff  

on the guest it yields:

vagrant@vvv:~$ ip addr show  1: lo:  mtu 16436 qdisc noqueue state UNKNOWN       link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00      inet 127.0.0.1/8 scope host lo      inet6 ::1/128 scope host          valid_lft forever preferred_lft forever  2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000      link/ether 08:00:27:12:96:98 brd ff:ff:ff:ff:ff:ff      inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0      inet6 fe80::a00:27ff:fe12:9698/64 scope link          valid_lft forever preferred_lft forever  3: eth1:  mtu 1500 qdisc pfifo_fast state UP qlen 1000      link/ether 08:00:27:2c:d4:3e brd ff:ff:ff:ff:ff:ff      inet 192.168.50.4/24 brd 192.168.50.255 scope global eth1  

For now, all I want to do is access the web server on the virtual machine, whatever way works. I have tried a variety of things, just shooting in the dark. I would be happy to provide any specific info. Any help or suggestions would be greatly appreciated

Answer by Terry Wang for Unable to connect to Vagrant private network from host


Based on the output provided, the box has 2 network interfaces, 1 is the default NAT and the other private - ask you said.

The reason why you are not able to access the web site hosted within the VM thru the private interface: it could be that host eth0 or wlan0 IP address is not in the same network as the private interface -> 192.168.50.4/24 and there is no route.

To access the the site hosted by the web server within the guest, you have the following options:

1. NAT port forwarding

Forward the web port, e.g. 80 to host's 8080 (you can't use 80 because it is a privileged port on *NIX). Add the following

Vagrant.configure("2") do |config|    config.vm.network "forwarded_port", guest: 80, host: 8080,      auto_correct: true  end  

NOTE: auto_correct will resolve port conflicts if the port on host is already in use.

DO a vagrant reload and you'll be able to access the site via http://localhost:8080/

2. Public Network (VirtualBox Bridged networking)

Add a public network interface

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

Get the IP of VM after it is up and running, port forwarding does NOT apply to bridged networking. So you'll be accessing the site by using http://IP_ADDR, if within the VM it binds to 80, otherwise specify the port.

Answer by laertiades for Unable to connect to Vagrant private network from host


I ended up getting the private network to work as well by deleting it within Virtual Box. When I recreated it again with vagrant up, the ip config became:

vboxnet0:  mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000      link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff      inet 192.168.50.1/24 brd 192.168.50.255 scope global vboxnet0         valid_lft forever preferred_lft forever  

Answer by Alfredo Baldoceda for Unable to connect to Vagrant private network from host


I had a similar issue on my Mac. VirtualBox uses host only for private networks. To use as an internal network I had to add this to the private network configuration:

"virtualbox__intnet: true"  

Answer by Willie Wheeler for Unable to connect to Vagrant private network from host


One more possibility just for future reference.

Normally when you create VMs using private networking, Vagrant (Virtualbox? not sure) creates corresponding entries in the host's routing table. You can see these using

netstat -rn  

Somehow my host had gotten into a state where creating the VMs did not result in new routes appearing in the routing table, with the corresponding inability to connect. Again you can see the routes not appearing using the command above.

Creating the route manually allowed me to reach the VMs. For example:

sudo route -nv add -net 10.0.4 -interface vboxnet  

(Substitute the appropriate network and interface.) But I didn't want to have to do that.

Based on this question, I tried restarting my host and Vagrant started automatically creating the routing table entries again.

Not sure exactly what the issue was, but hopefully this helps somebody.

Answer by Phreditor for Unable to connect to Vagrant private network from host


This may not apply exactly, but "private network" in the title brought me here and others may benefit that are trying to run multiple guest boxes on Mac OS X:

I use "private_network" and don't do any port forwarding. I.e. I access my VMs by hosts like "project1.local", "project2.local".

So, I was surprised when I tried to launch a second box (a scotch/box ubuntu for LAMP) and it refused to launch with an error (excerpt):

"...The forwarded port to 2222 is already in use on the host machine..."  

The error message's proposed solution doesn't work. I.e. add this to your Vagrantfile:

config.vm.network :forwarded_port, guest: 22, host: 1234  #Where 1234 would be a different port.  

I am not sure why it happens because I've run multiples before (but not scotch/box). The problem is that even if you use private_network, Vagrant uses port forwarding for SSH.

The solution is to set ports SPECIFICALLY FOR SSH by adding this to your Vagrant files:

# Specify SSH config explicitly with unique host port for each box  config.vm.network :forwarded_port,    guest: 22,    host: 1234,    id: "ssh",    auto_correct: true  

Note: auto_correct may make non-unique port #s work, but I haven't tested that.

Now, you can run multiple VMs at the same time using private networking.

(Thanks to Aaron Aaron and his posting here: https://groups.google.com/forum/#!topic/vagrant-up/HwqFegoCXOc)

Answer by medina for Unable to connect to Vagrant private network from host


Or you can just try "vagrant up" and then "vagrant provision". Most of the time it fixes the problem.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.