Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guest vm hostname duplicated in /etc/hosts #69

Closed
kminder opened this issue Jan 30, 2014 · 2 comments
Closed

Guest vm hostname duplicated in /etc/hosts #69

kminder opened this issue Jan 30, 2014 · 2 comments

Comments

@kminder
Copy link

kminder commented Jan 30, 2014

I'm not sure if this is intentional or not but the hostname of the guest end up duplicated in /etc/hosts. See the Vagrantfile and the resulting /etc/hosts below. Notice how vm.local is present in both the 127.0.0.1 and 192.168.200.100 line. I was expecting/hoping that vm.local and vm would be removed from 127.0.0.1 and both would end up on 192.168.200.100. I do understand that I could add an alias to get vm on 192.168.200.100.

A potential suggestion could be to add a config option like
config.hostmanager.manage_guest_localhost = true
This would result in the 127.0.0.1 line being "cleansed" of values from config.vm.hostname.

For now I added a shell provisioner that does this
sed -i 's/\(127\.0\.0\.1\)\s*.*\s*\(localhost\)\s/\1\t\2 /' /etc/hosts

Perhaps there is a better way I should be doing this.

These are my versions.

Vagrant: 1.4.3
vagrant-hostmanager (1.3.0)

This is my Vagrantfile.

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "centos"
  config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130427.box"
  config.vm.hostname = "vm.local"
  config.vm.network :private_network, ip: "192.168.200.100"
  config.hostmanager.enabled = true
end

This is the resulting /etc/hosts on my guest vm.

127.0.0.1   vm.local vm localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.100 vm.local    # VAGRANT ID: 812be983-648d-4313-b4f8-10fa673bcb98
@pbitty
Copy link
Contributor

pbitty commented Feb 22, 2014

Hi @kminder, the 127.0.0.1 ... line in the hosts file is changed by vagrant itself when it configures the guest's hostname. vagrant-hostmanager only touches the lines that it adds.

Cleaning the 127.0.0.1 line could be done, as you suggested, but at a first glance it looks to me like this is a very specific case of a more general issue.

At the moment, there are two guests OS types where vagrant updates /etc/hosts in a similar way: Redhat/Centos and Debian/Ubuntu. In the Debian case, it actually adds a 127.0.1.1 line - I'm not exactly sure why. I think if we were to edit only the 127.0.0.1 line, we would still have this issue in Debian/Ubuntu guests.

It seems to me that in general we would want hostmanager to remove any names in /etc/hosts that conflict with the ones it is to add.

I think this would involve some parsing etc/hosts to find these entries, and for each one, take out the conflicting names in that line while leaving the rest of the entry if there are other names, (skipping comment lines and so on).

What do you think?

Is this something you would be interested in contributing?

@pbitty
Copy link
Contributor

pbitty commented Apr 27, 2014

Closing this. If you'd like to look into it further, feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants