Create a gist now

Instantly share code, notes, and snippets.

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 <>
- Logging into the vm with a regular ssh command
See <>
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!

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

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"]

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

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

👍 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.

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

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