Adding /etc/hosts entry to host machine on vagrant up

Michael Robinson picture Michael Robinson · May 18, 2013 · Viewed 36.3k times · Source

Is it possible for one to modify files on the host machine during the vagrant up process? For example, adding an entry to the host machine's /etc/hosts file to avoid having to do this manually?

Answer

Michael Robinson picture Michael Robinson · May 18, 2013

The solution is to use vagrant-hostsupdater

vagrant plugin install vagrant-hostsupdater

This plugin adds an entry to your /etc/hosts file on the host system.

On up and reload commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.

On halt, suspend and destroy, those entries will be removed again.