daveypoos's avatar

Vagrant SSH so SLOW - but only with internet access!

Hey guys,

I'm totally sold on using Vagrant / Homestead but I need some help with a really peculiar problem...

I've installed Virtualbox, Vagrant and Homestead fine: the files are syncing beautifully, the database is connecting and I can see my app at the url of my choice e.g. myapp.local:8000.

HOWEVER, it takes an eternity (well, about 30 seconds) to ssh in (using both vagrant ssh and ssh vagrant@127.0.0.1...) and even longer to issue commands (30 seconds - 1 minute). This also affects actually using my app with page loads taking forever.

Here comes the funny part: As soon as I disconnect from the internet, everything suddenly works perfectly! SSH, commands and browsing my app become lightning quick.

Any ideas guys?

0 likes
15 replies
daveypoos's avatar

No luck! I added 'UseDNS no' and 'GSSAPIAuthentication no' to the sshd_config and restart (with service ssh restart) and had no effect.

Any other ideas?

bashy's avatar

Sounds like a DNS lookup is taking ages to complete. Have you tried adding the entry in /etc/hosts?

bashy's avatar

Every time you connect via SSH, it does a reverse lookup on the IP connecting. Make sure something is in the hosts file for it to use. 127.0.0.1 localhost or whatever the IP is local

stefanbauer's avatar

On your Mac's, when i am not wrong. I think also it is a lookup problem.

bashy's avatar

VM, that will have a separate hosts file to your Mac.

bashy's avatar

Not sure that connecting to SSH is 127.0.0.1 maybe it's 127.0.10.33 or something

simplenotezy's avatar

Should I add:

127.0.0.1 homestead homestead

to my hosts file?

willvincent's avatar

If you're using homestead just use this to ssh in: homestead ssh

If you're using vagrant, but not homestead, cd into the directory the Vagrantfile is in, and then just do vagrant ssh

That should be faster, and it's definitely less to type :)

bashy's avatar

@canfiax Is that for the same problem?

Think a better way is to disable DNS for SSH lookups

sudo nano /etc/ssh/sshd_config

// change from yes to no (or add it if it's not there)
UseDNS no
sitesense's avatar

That hosts file entry looks bad. it should look like below:

192.168.10.10    myapp.dev

Where myapp.dev is the same as the sites mapping in your Homestead.yaml file:

sites:
    - map: myapp.dev
      to: /home/vagrant/Code/myapp/public

Regarding the slowness, here's something I came across:

It could very easily be that the wrong thing is getting set in /etc/resolv.conf. Either the contents point to the wrong DNS server (non-existant, broken, or behind a firewall (the one at work) or your network is not providing you access to the network where the listed nameserver resides (e.g., the internet, or your local router/gateway device.

When the VM is acting slow, as root, edit /etc/resolv.conf and comment out everything in it.

See if operations become normal speed again. If they do, then access to DNS is what is slowing you down.

Then ping 8.8.8.8. If it works, edit /etc/resolv.conf and put this as the first line:

nameserver 8.8.8.8

EDIT: I believe 8.8.8.8 is Google's DNS service. If you can't ping that from your VM, it looks like you may have a firewall preventing access.

Try disabling any firewall and see if that improves things. If it does, you need to allow access through it for your VM.

hlx8xlh's avatar

i find a nice method; connect directly;

ssh [email protected] -p22

maybe, you can add the above command to your ~/.bashrc as

alias vsh="ssh [email protected] -p22"

then source ~/.bashrc, use vsh command in git bash

Please or to participate in this conversation.