Open karlkfi opened 8 years ago
The above report is using a CentOS 7.2 guest on VirtualBox.
Curl version:
$curl --version
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.19.1 Basic ECC zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz
Removing the Vagrant added alias results in the desired behavior:
$ curl -v a1.dcos
* About to connect() to a1.dcos port 80 (#0)
* Trying 192.168.65.111...
* Connection refused
* Failed connect to a1.dcos:80; Connection refused
* Closing connection 0
curl: (7) Failed connect to a1.dcos:80; Connection refused
FYi I've run into the same issue. I get around it by automating stripping out the offending entries with a shell provisioner. Something like this:
hostfix = 'sed "s/\\(127.0.0.1.*\\)$(hostname)\\(.*\\)/\\1\\2/" < /etc/hosts > /tmp/hosts && mv /tmp/hosts /etc/hosts'
...
node.vm.provision :shell, inline: hostfix
Yeah, I've had to use something similar. Would be nice if vagrant-hostmanager did it for us tho.
I've lost yesterday because of this issue - I couldn't figure out why rancher/docker weren't working properly!
IMO, the correct thing to do here is for vagrant to not add that line to /etc/hosts. I wonder if it can be disabled?
I've been running into the same issue. I'm using Vagrant 1.8.6 and CentOS 7.2 based vagrant boxes.
FWIW, I use a provisioning step to work around this issue:
machine_types.each do |name, machine_type|
config.vm.define name do |machine|
machine.vm.provision :shell, inline: "sed -i'' '/^127.0.0.1\\t#{machine.vm.hostname}\\t#{name}$/d' /etc/hosts"
end
end
Handy work around. Thank you.
I ran into this problem and wasted nearly a day trying to figure out why a couple of my services (e.g., Spark and ZooKeeper) failed to work. In my case, I use Vagrant with Ansible as my provisioner. Here's the equivalent workaround for Ansible. Simply, add this to one of your Ansible roles:
- name: prevent hostname from binding to the loopback address
command: sed -i '/127.0.0.1\t{{ansible_hostname}}\t{{ansible_hostname}}/d' /etc/hosts
ignore_errors: true
changed_when: true
Recent versions of Vagrant set the VM name and hostname as aliases to 127.0.0.1 at the top of
/etc/hosts
on CentOS. This seems to change the behavior of hostname resolution performed by Name Server Switch such that 127.0.0.1 is returned instead of the IP added by vagrant-hostmanager.Example:
In this dcos-vagrant example, there are several VMs, one of which is named
a1
with the hostnamea1.dcos
.Host resolution works fine for many tools, like
host
,nslookup
anddig
, but fails for tools that use NSS likeping
andcurl
.ping
hits127.0.0.1
instead of192.168.65.111
:curl a1.dcos
tries127.0.0.1
first and only tries192.168.65.111
if127.0.0.1
is refused:Rearranging
/etc/hosts
to put hostmanager aliases on top fixesping
:But curl still tried 127.0.0.1 first: