Vagrant Hostnames

Instead of port forwarding or IP address,I access vagrant VMs by hostname.

Being too lazy to set them up by hand, I use the hostsupdater plugin. This plugin will change the /etc/hosts file as you start and stop VMs.

$ vagrant plugin install vagrant-hostsupdater

Install the plugin via the vagrant command line. Then add these lines to your Vagrantfile.

Vagrant.configure("2") do |config|
  config.vm.hostname = "myprojectname.vm"
  config.hostsupdater.remove_on_suspend = true
end

Now every time you run vagrant up a hostname will be setup pointing to the VM.