Can't connect vagrant localhost when network change (but ssh works)

3,367 views
Skip to first unread message

Nico

unread,
May 14, 2015, 4:22:02 AM5/14/15
to vagra...@googlegroups.com
Hello all,

I have a problem since yesterday that i'm not able to fix.

I have installed Vagrant when i was at work. Everything was working correctly for about a week.

I have brought my computer at home (work is hard ^^), but even if i'm able to up vagraht and to ssh it, i can't reach it through my local.

When i try to get http://localhost:4567, it doesn't work, but when i'm at work, there is no problem.

It seems that vagrant has probably stuck to my work network and doesn't allow a connection on another network.

Anyway, when i try to get only localhost, i have the Apache2 Ubuntu Default Page...

Also, when i try to curl the localhost page (on port 4567) from my local, i have an empty reply from server (error 52), and the same when i'm connected to Vagrant.

Well, everything else work, because i can make a "vagrant ssh", ifconfig shows me that vagrant is well connected on network, i can also connect vagrant through an ssh connection as root (ssh root@...).

This is the content of my VagrantFile :


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

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "lucid64"

  # The url from where the 'config.vm.box' box will be fetched if it
  # doesn't already exist on the user's system.
  # config.vm.box_url = "http://domain.com/path/to/above.box"

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network :forwarded_port, guest: 80, host: 8080
  config.vm.network:forwarded_port, host:4567, guest:80
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network :private_network, ip: "192.168.33.10"
 
  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
   config.vm.network :public_network

  # If true, then any SSH connections made will enable agent forwarding.
  # Default value: false
  # config.ssh.forward_agent = true

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  config.vm.synced_folder ".", "/vagrant", :group => "www-data", :mount_options => ['dmode=777','fmode=777']

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider :virtualbox do |vb|
  #   # Don't boot with headless mode
  #   vb.gui = true
  #
  #   # Use VBoxManage to customize the VM. For example to change memory:
  #   vb.customize ["modifyvm", :id, "--memory", "1024"]
  # end
  #
  # View the documentation for the provider you're using for more
  # information on available options.

  # Enable provisioning with Puppet stand alone.  Puppet manifests
  # are contained in a directory path relative to this Vagrantfile.
  # You will need to create the manifests directory and a manifest in
  # the file lucid64.pp in the manifests_path directory.
  #
  # An example Puppet manifest to provision the message of the day:
  #
  # # group { "puppet":
  # #   ensure => "present",
  # # }
  # #
  # # File { owner => 0, group => 0, mode => 0644 }
  # #
  # # file { '/etc/motd':
  # #   content => "Welcome to your Vagrant-built virtual machine!
  # #               Managed by Puppet.\n"
  # # }
  #
  # config.vm.provision :puppet do |puppet|
  #   puppet.manifests_path = "manifests"
  #   puppet.manifest_file  = "site.pp"
  # end

  # Enable provisioning with chef solo, specifying a cookbooks path, roles
  # path, and data_bags path (all relative to this Vagrantfile), and adding
  # some recipes and/or roles.
  #
  # config.vm.provision :chef_solo do |chef|
  #   chef.cookbooks_path = "../my-recipes/cookbooks"
  #   chef.roles_path = "../my-recipes/roles"
  #   chef.data_bags_path = "../my-recipes/data_bags"
  #   chef.add_recipe "mysql"
  #   chef.add_role "web"
  #
  #   # You may also specify custom JSON attributes:
  #   chef.json = { :mysql_password => "foo" }
  # end

  # Enable provisioning with chef server, specifying the chef server URL,
  # and the path to the validation key (relative to this Vagrantfile).
  #
  # The Opscode Platform uses HTTPS. Substitute your organization for
  # ORGNAME in the URL and validation key.
  #
  # If you have your own Chef Server, use the appropriate URL, which may be
  # HTTP instead of HTTPS depending on your configuration. Also change the
  # validation key to validation.pem.
  #
  # config.vm.provision :chef_client do |chef|
  #   chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
  #   chef.validation_key_path = "ORGNAME-validator.pem"
  # end
  #
  # If you're using the Opscode platform, your validator client is
  # ORGNAME-validator, replacing ORGNAME with your organization name.
  #
  # If you have your own Chef Server, the default validation client name is
  # chef-validator, unless you changed the configuration.
  #
  #   chef.validation_client_name = "ORGNAME-validator" 
  end

I really hope that you will be able to help me, because i really don't know what to do :)

Thank you all for reading.

Regards

Nico

Alvaro Miranda Aguilera

unread,
May 14, 2015, 5:29:16 AM5/14/15
to vagra...@googlegroups.com
Hello

What OS is your host?

When you are at HOME, do you use any VPN software?

At Work do you have PROXY ?

Alvaro.
> --
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nico

unread,
May 14, 2015, 5:55:55 AM5/14/15
to vagra...@googlegroups.com
Hi,

Thanks for your reply.

You're right i've forgotten my OS, i'm using Ubuntu 14.04.

At home, no vpn nor proxy.
At work, i'm not sure, but i don't think that we are using a proxy. But perhaps because i know that with have an internet box, which transfert connection to 3 routers.

The hell is that i can ping, make apt-get from vagrant when i'm log in ^^ So Internet surely works =)

My local seems to not understand what to reach when i up vagrant and ask to get localhost:4567 :/

Thanks a lot

Nico

Alvaro Miranda Aguilera

unread,
May 14, 2015, 6:04:19 AM5/14/15
to vagra...@googlegroups.com
On Thu, May 14, 2015 at 9:55 PM, Nico <nicolas...@gmail.com> wrote:
>> config.vm.network:forwarded_port, host:4567, guest:80

ok

We have done this before, but happy to go again :D

config.vm.network:forwarded_port, host:4567, guest:80

On the guest do:

sudo netstat -anp | grep ':80'

If you see :: that is ipv6

what have happened in the past, is that when you don't configure a
hostname, the line localhost gets evaluated to ipv6 sometimes

Add this to your vagrantfile

config.vm.hostname = "lucid64.myfakedomain"

Then:

vagrant reload

test again.. if doesn't work, provide:


cat /etc/hosts

sudo netstat -anp | grep ':80'

Nico

unread,
May 14, 2015, 7:52:31 AM5/14/15
to vagra...@googlegroups.com
Hello,

Thanks for your quick answer ^^

This what i have on my local on /etc/hosts


127.0.0.1    localhost
127.0.1.1    nicolasgirot-SATELLITE-S50-B

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


 And what i have with  sudo netstat -anp | grep ':80'

tcp6       0      0 :::80                   :::*                    LISTEN      1366/apache2   
tcp6       0      0 2a01:e34:ef43:6f9:36110 2a00:1450:4007:80d:::80 TIME_WAIT   -              
tcp6       0      0 2a01:e34:ef43:6f9:59206 2607:f8b0:4007:80a::443 ESTABLISHED 3723/firefox   

I have also add in the vagrantFile :

config.vm.hostname = "lucid64.localhost"

Well, still not working.
When i try to access localhost:4567, still no answer...

I have desactivate ipv6 for my local and the virtual machine...

Something strange, is that now i can open localhost:4567/phpmyadmin !! Trying to connect, but that fails.
The error message is :

phpMyAdmin -

Erreur lors du démarrage de la session, veuillez vérifier les erreurs indiquées par PHP ou dans le fichier témoin du serveur web, et configurer PHP correctement.

=> Error when starting session, please check PHP erros ...

:/

Thank you very much for all your answer ;)

Nico

unread,
May 14, 2015, 8:22:39 AM5/14/15
to vagra...@googlegroups.com
I've read that some says to start the vm on 0.0.0.0.

This is the adress : http://stackoverflow.com/questions/23840098/empty-reply-from-server-cant-connect-to-vagrant-vm-w-port-forwarding

How to do that with Vagrant??

Alvaro Miranda Aguilera

unread,
May 14, 2015, 4:58:23 PM5/14/15
to vagra...@googlegroups.com
Hello

I need the output from the VM please

cat /etc/hosts
netstat -anp | grep ':80'

Nico

unread,
May 15, 2015, 2:26:02 AM5/15/15
to vagra...@googlegroups.com
Hello Alvaro,

Sorry i was not able to answer your sooner.

This is what i have, and there is a difference with what i have at work (i have just checked) :

At home :

root@lucid64:/home/vagrant# cat /etc/hosts

127.0.0.1    localhost
127.0.1.1 lucid64.localhost lucid64
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback

fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

root@lucid64:/home/vagrant# netstat -anp | grep ':80'
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1022/apache2

for an ifconfig :

root@lucid64:/home/vagrant# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:36:71:5f 
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:414 errors:0 dropped:0 overruns:0 frame:0
          TX packets:263 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:45177 (45.1 KB)  TX bytes:36093 (36.0 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:bf:fe:05 
          inet addr:192.168.1.12  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:34 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5493 (5.4 KB)  TX bytes:3066 (3.0 KB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:560 (560.0 B)  TX bytes:560 (560.0 B)

Now, at work, without having change anything (and it works with success) :

 For the cat /etc/hosts, nothing change (which is i think logical).

Nevertheless for netstat :

root@lucid64:/home/vagrant# netstat -anp | grep ':80'
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1083/apache2   
tcp        0      0 10.0.2.15:80            10.0.2.2:34881          TIME_WAIT   -              
tcp        0      0 10.0.2.15:80            10.0.2.2:34878          TIME_WAIT   -              
tcp        0      0 10.0.2.15:80            10.0.2.2:34877          TIME_WAIT   -              
tcp        0      0 10.0.2.15:80            10.0.2.2:34862          TIME_WAIT   -              
tcp        0      0 10.0.2.15:80            10.0.2.2:34879          TIME_WAIT   -    

Well, any idea of wtf is this???

I have left into the vagrantFile the line that you told me to write ( config.vm.hostname = "lucid64.localhost")

Thanks for your help :)

Nico

unread,
May 15, 2015, 2:32:16 AM5/15/15
to vagra...@googlegroups.com
Here the ifconfig at work :

root@lucid64:/vagrant# ifconfig

eth0      Link encap:Ethernet  HWaddr 08:00:27:36:71:5f 
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:969 errors:0 dropped:0 overruns:0 frame:0
          TX packets:902 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:111668 (111.6 KB)  TX bytes:643674 (643.6 KB)


eth1      Link encap:Ethernet  HWaddr 08:00:27:bf:fe:05 
          inet addr:192.168.10.133  Bcast:192.168.10.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:321 errors:0 dropped:0 overruns:0 frame:0
          TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:58868 (58.8 KB)  TX bytes:2146 (2.1 KB)


lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:32 errors:0 dropped:0 overruns:0 frame:0
          TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2438 (2.4 KB)  TX bytes:2438 (2.4 KB)

Alvaro Miranda Aguilera

unread,
May 15, 2015, 3:09:36 AM5/15/15
to vagra...@googlegroups.com
Hello,

If you use the IP on eth1, I think should work, netstat is working file:

http://192.168.10.133:80

do you have the vm running? or you stop it and restart in the new place?

I wonder if a vagrant reload will fix the issue.

Can you sent to me the following:

vagrant ssh-config
Vagrantfile

?

Nico

unread,
May 15, 2015, 3:25:33 AM5/15/15
to vagra...@googlegroups.com

Well, here, at work, when i try to access through ip adress it works. But i tried at home in the same conditions, and it didn't work.

My vm is running and i start it here when i arrived tomorrow.

I also tried a reload (several actually) ^^

This is the ssh config :

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /root/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

And for the vagrantFile, you will find it on my first message, i only add the line you told me to write in it ;)

 

Nico

unread,
May 16, 2015, 12:48:27 PM5/16/15
to vagra...@googlegroups.com
I just up the topic.
Alvaro are you still there ^^

Nico

unread,
May 20, 2015, 10:00:47 AM5/20/15
to vagra...@googlegroups.com
Hey there,

Just to say that my problem is no solved!

Thank you very much Alvaro for All!!!!

Well, it was not, in fact a vagrant problem. It came from my application (i'm using cakephp).

In fact, i had to remove all tmp files in app/tmp, and then, check my.cnf of mysql.
I don't know why and when i did this, but i had added a bind address. So connection to db was impossible.

The problem with cake tmp files is still a mystery...

Thanks again Alvaro!


Reply all
Reply to author
Forward
0 new messages