Prevent Vagrant from manipulating /etc/hosts

2

When config.vm.hostname is set in a Vagrantfile, Vagrant manages the hostname. Furthermore, and this is the bad part for me, it manipulates /etc/hosts to contain the hostname pointing to 127.0.0.1 (localhost).

This hardly makes sense... especially not when having a public networking interface in place. Problems arising are when applications use the hostname to determine the IP address to bind to.

This is a miminal example Vagrant file to demonstrate the issue

Vagrant.configure(2) do |config|
  config.vm.box = "centos/7"
  config.vm.network :public_network, ip: "192.168.2.100", netmask: "255.255.255.0", bridge: ["eno1", "enp6s0"]
  config.vm.hostname = "test.mydomain.xyz"
end

The result is an /etc/hosts file as shown below.

127.0.0.1   test.mydomain.xyz test localhost localhost.localdomain localhost4 localhost4.localdomain4                                                                                 
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6                                                                                                        

So my questions are

  1. How can I prevent vagrant from manipulating the /etc/hosts file this way? Since I manage the hosts file myself, can I prevent it to touch the hosts file at all? There seems to be no option in Vagrant 1.8.1 for that.
  2. How does this default Vagrant behavior makes sens at all? What do I miss?

Thanks for your help!

John

Posted 2016-04-21T19:29:48.427

Reputation: 98

I made this a topic at Vagrant's GIThub page https://github.com/mitchellh/vagrant/issues/7263

– John – 2016-05-04T17:19:26.650

No answers