Search code examples
linuxubuntuvagrantvirtual-machinevagrantfile

Change Hostname Vagrant


I've setup two vagrant VMs of ubuntu - one for slave and one for master.I frequently get confused after logging into the vagrant VM using vagrant ssh which machine I'm in. What do I call this green string in the screenshot and how do I change this this for both slave and master machines like ubuntuslave and ubuntumaster?

enter image description here


Solution

  • The string in green is of the format <username>@<hostname>. So in order to differentiate between your two servers, you need to change the hostname, to give you something like ubuntu@ubuntu-slave.

    To do this, you need to add the hostname configuration option to your Vagrantfile:

    Vagrant.configure("2") do |config|
       config.vm.box = "precise32"
       config.vm.hostname = "ubuntu-slave"
       config.vm.network :private_network, ip: "192.168.0.10"
    end
    

    This, however, will only update your hostname after you recreate the VMs. If you aren't planning on doing this, you will also need to modify the hostname within Ubuntu itself.