Skip to content


Repository files navigation


This vagrant plugin adds host file entries to the host pointing to the guest VM, using the GoodHosts cli tool. This plugin is based on vagrant-hostsupdater and aims to be compatible with the same config parameters.

On up, resume and reload commands, it tries to add the hosts if they do not already exist in your hosts file. If it needs to be added, you will be asked for the sudo password to make the necessary edits.

On halt, destroy, and suspend, those entries will be removed again. By setting the config.goodhosts.remove_on_suspend = false, suspend and halt will not remove them.


vagrant plugin install vagrant-goodhosts

To uninstall :

vagrant plugin uninstall vagrant-goodhosts

To update the plugin:

vagrant plugin update vagrant-goodhosts

Installation from Gem file

The gem file is released with every release and you can install it with vagrant as it is a plugin after all.
Affter downloading the file run this command to install manually:

vagrant plugin install vagrant-goodhosts-*.gem


You currently only need the hostname and a :private_network network with a fixed IP address. :private_network, ip: ""
config.vm.hostname = "" # This is not used by the plugin
config.goodhosts.aliases = ["", ""]

This IP address and the hostname will be used for the entry in the /etc/hosts file.

vagrant-hostsupdater conflicts

The original plugin has the issue of be executed in any vagrant environment, also that is not using and will add a rule in the hosts file that is not generated by this one. To avoid issues is better to remove that plugin and in case update accordingly the Vagrantfile if use it. Require just a change of the reference of the plugin name as the example above.

Multiple private network adapters

If you have multiple network adapters i.e.: :private_network, ip: "" :private_network, ip: ""

You can specify which hostnames are bound to which IP by passing a hash mapping the IP of the network to an array of hostnames to create, e.g.:

config.goodhosts.aliases = {
    '' => ['', ''],
    '' => ['', '']

This will produce /etc/hosts entries like so:

Keeping Host Entries After Suspend/Halt

To keep your /etc/hosts file unchanged simply add the line below to your VagrantFile:

config.goodhosts.remove_on_suspend = false

This disables vagrant-goodhosts from running on suspend and halt.

Disable file hosts clean

If you want /etc/hosts file cleaned add in your VagrantFile:

config.goodhosts.disable_clean = false

This enable vagrant-goodhosts from running the clean command in every call.

Suppressing prompts for elevating privileges

These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
The command path is printed in red when there are errors with Vagrant eg. if the sudo password is entered incorrectly for 3 times.
If you understand the risks that go with supressing them, here's how to do it.

Linux/OS X: Passwordless sudo

To allow vagrant to automatically update the hosts file without asking for a sudo password, add one of the following snippets to a new sudoers file include, i.e. sudo visudo -f /etc/sudoers.d/vagrant_goodhosts. The command path is printed when there are errors with Vagrant, check the output marked in red.

For Ubuntu and most Linux environments:

%sudo ALL=(root) NOPASSWD: [the-command-path]

An example complete:

%sudo ALL=(root) NOPASSWD: /home/user/sites/vvv/.vagrant/plugins/gems/3.1.2/gems/vagrant-goodhosts-1.1.6/lib/vagrant-goodhosts/bundle/cli_amd64_linux

For MacOS:

%admin ALL=(root) NOPASSWD: [the-command-path]

Replace in both %sudo/%admin with the username it if it is not working for you.

Windows: UAC Prompt

You can use cacls or icacls to grant your user account permanent write permission to the system's hosts file. You have to open an elevated command prompt; hold ❖ Win and press X, then choose "Command Prompt (Admin)"

cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W

Generate The Development Version

If you would like to install vagrant-goodhosts to make contributions or changes, run the following commands::

git clone vagrant-goodhosts
cd vagrant-goodhosts
vagrant plugin install vagrant-goodhosts-*.gem

Test the plugin

You need to run a Vagrant machine with the minimum settings specified in the Usage section, it is enough a turn on and off and in the meantime if the hosts file in your machine is written in the right way.