我設置了虛擬機的主機名,我想在本機上訪問虛擬機的主機名,能夠手工編輯本機上的 hosts 文件。更方便的方法是使用 Vagarnt hostmanager 這個插件。node
https://github.com/devopsgroup-io/vagrant-hostmanager39git
vagrant plugin install vagrant-hostmanager
返回:github
Installing the 'vagrant-hostmanager' plugin. This can take a few minutes... Installed the plugin 'vagrant-hostmanager (1.8.2)'!
在 Vagrantfile 裏面,能夠爲虛擬機添加下面的配置:.net
config.hostmanager.enabled = true config.hostmanager.manage_host = true config.hostmanager.manage_guest = true
在定義虛擬機的時候,能夠添加 hostname 來設置虛擬機的主機名:插件
config.vm.define "node1" do |node1| node1.vm.network "private_network", ip: "192.168.33.11" node1.vm.hostname="node1" end
啓動虛擬機之後會自動更新虛擬機的主機名,同時也會更新本地主機上的 hosts 文件裏的內容。vagrant
或者咱們也能夠手工的去更新,執行命令:code
vagrant hostmanager
返回:ip
[manager1] Updating /etc/hosts file... [worker1] Updating /etc/hosts file... [worker2] Updating /etc/hosts file...