Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
speeding up DNS/SSH connections in vagrant
- Tune /etc/ssh/sshd_config
UseDNS no # Disable DNS lookups
GSSAPIAuthentication no # Disable negotation of slow GSSAPI
don't forget to restart it, use a script provider to set it , or create it with veewee or snapshot it
- Tune Vagrantfile
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
See <http://serverfault.com/questions/453185/vagrant-virtualbox-dns-10-0-2-3-not-working?rq=1>
- Logging into the vm with a regular ssh command
See <http://blog.codeboutique.com/post/creating-debian-squeeze-box-for-vagrant>
vagrant ssh-config vmname | ssh -t -t -F/dev/stdin vmname
Use the -t -t to overcome the pseudoterminal warning
- Now use a control connnection for ssh
(as it seems that the cli invocation of vagrant takes a couple of seconds ....)
Setup the control session:
vagrant ssh-config vmname | ssh -t -t -F/dev/stdin -o 'ControlMaster auto' -o 'ControlPath ~/.ssh/vagrant' vmname
Use it for fast login
ssh -o 'ControlMaster auto' -o 'ControlPath ~/.ssh/vagrant' vmname
Now it logins in a matter of milliseconds!
@nicobrevin

This comment has been minimized.

Show comment
Hide comment
@nicobrevin

nicobrevin Dec 30, 2013

boom, this worked a treat, test suite going a lot quicker!

boom, this worked a treat, test suite going a lot quicker!

@alanwsmith

This comment has been minimized.

Show comment
Hide comment
@alanwsmith

alanwsmith Aug 2, 2014

For those new to Vagrantfile setup, the vb.customize line needs to be in a config.vm.provider block. For example:

config.vm.provider :virtualbox do |vb|
  vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end

And, in this case, it assumes you are using VritualBox.

For those new to Vagrantfile setup, the vb.customize line needs to be in a config.vm.provider block. For example:

config.vm.provider :virtualbox do |vb|
  vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end

And, in this case, it assumes you are using VritualBox.

@alanwsmith

This comment has been minimized.

Show comment
Hide comment
@alanwsmith

alanwsmith Aug 2, 2014

Unless a name is set explicitly, change all instances of vmname in the walkthrough to default. That was a stumbling block for me.

Unless a name is set explicitly, change all instances of vmname in the walkthrough to default. That was a stumbling block for me.

@geekflyer

This comment has been minimized.

Show comment
Hide comment
@geekflyer

geekflyer Aug 18, 2014

👍 awesome, thanks!! It connects pretty much instantly now and I can conveniently issue commands to the vm, without being locked in the session. Works with OS X 10.9 as host, Ubuntu 14.04 as guest.

👍 awesome, thanks!! It connects pretty much instantly now and I can conveniently issue commands to the vm, without being locked in the session. Works with OS X 10.9 as host, Ubuntu 14.04 as guest.

@drewwells

This comment has been minimized.

Show comment
Hide comment
@drewwells

drewwells Feb 10, 2015

Can virtualbox set UseDNS no, or does that need to be configured with chef/puppet?

Can virtualbox set UseDNS no, or does that need to be configured with chef/puppet?

@sunnypp

This comment has been minimized.

Show comment
Hide comment
@sunnypp

sunnypp Oct 23, 2017

This has worked! From 7 seconds regular ssh to almost instant. Am on macOS Sierra 10.12.6 with Centos as guest.

On top of the above, I also copied the output of vagrant config and used echo '...content...' | ssh ... instead. This saves time since vagrant config takes time to load.

I have been looking for a solution for slow Vagrant ssh connections on Mac for months (though interrupted by daily work).

Just in case someone is in doubt, I ran vagrant ssh and then sudo vi /etc/ssh/sshd_config. Did a /GSSAPI to search where it is and added UseDNS no above the GSSAPI section and switched off GSSAPIAuthentication.

sunnypp commented Oct 23, 2017

This has worked! From 7 seconds regular ssh to almost instant. Am on macOS Sierra 10.12.6 with Centos as guest.

On top of the above, I also copied the output of vagrant config and used echo '...content...' | ssh ... instead. This saves time since vagrant config takes time to load.

I have been looking for a solution for slow Vagrant ssh connections on Mac for months (though interrupted by daily work).

Just in case someone is in doubt, I ran vagrant ssh and then sudo vi /etc/ssh/sshd_config. Did a /GSSAPI to search where it is and added UseDNS no above the GSSAPI section and switched off GSSAPIAuthentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment