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

Hosts file does not work on newer versions of OSX #60

Closed
dpehrson opened this Issue Dec 24, 2013 · 11 comments

Comments

Projects
None yet
7 participants
@dpehrson

dpehrson commented Dec 24, 2013

If I get some time I may work on a pull request for this, but in the meantime I want to get it documented.

Problem: OSX ignores /etc/hosts entries unless they are at the TOP of the file.
Solution: Prepend instead of append when adding entries, at least on OSX.
Reference: http://thecoredump.org/2011/09/editing-the-hosts-file-in-mac-os-x-lion/

@pbitty

This comment has been minimized.

Contributor

pbitty commented Dec 24, 2013

Interesting. The post seem to imply that this is something that started in OSX 10.7. Do you know if this is the case, or whether it happens in earlier versions?

@dpehrson

This comment has been minimized.

dpehrson commented Dec 24, 2013

Honestly, I'm second guessing my bug report now after digging in more. I think it's the fact that I am using fake domains with real TLDs (fake-site.com) for local development since hostnames with completely bogus TLDs (my.app) work fine.

Strangely, Chrome can access the local development site fine, but Safari cannot, and system tools like ping can't resolve the hostname either.

This is definitely new with Mavericks, but I'm now not sure this is a vagrant-hostmanager issue, as such I am going to close my own issue until I have more information.

@dpehrson dpehrson closed this Dec 24, 2013

@dpehrson

This comment has been minimized.

dpehrson commented Feb 11, 2014

I'm reopening this as I have confirmed it, plus another issue:

http://stevegrunwell.com/blog/quick-tip-troubleshooting-etchosts-issues/

  1. Entries must be added to the TOP of /etc/hosts on OSX
  2. You cannot set multiple hostnames for one ip in one line. Each host must have it's own line

The way vagrant hostmanager currently writes the host file (at least on OSX) causes the aliases to be ignored by all apple software (safari, iOS simulator, even ping.) For some reason Chrome has no issues. Firefox works, but is very slow.

As soon as I tweaked the /etc/hosts entries, everything loaded quickly.

@dpehrson dpehrson reopened this Feb 11, 2014

@meckhardt

This comment has been minimized.

meckhardt commented Mar 31, 2014

👍

@acorncom

This comment has been minimized.

acorncom commented Mar 31, 2014

@dpehrson I read your comments with interest as I had issues on my end. Turned out my issues were unrelated (I'll open a separate issue). But I'm on a clean install of Mavericks (10.9.2) with a standard /etc/hosts file that works as expected with no bugs:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0 localhost

## vagrant-hostmanager-start id: 5aa2cdd8-dd34-4586-8205-2fece0986adb
192.168.200.20  dev.machine.name
## vagrant-hostmanager-end

ping, Safari and Chrome all work without issues.

Is it possible that your issues arise from something else? Did you do an upgrade install of your OS that might have had problems? Could you do a quick OS install to a second hard drive and test there? I'm not sure this is a vagrant issue per se ...

@delphyne

This comment has been minimized.

delphyne commented Mar 31, 2014

There is a bug in OSX related to having too many host aliases on the same line. It appears to break somewhere between 6 and 7 host aliases.

for example, in /etc/hosts (old version of hostmanager, but irrelevant since it's not a hostmanager bug)

192.168.56.3    dev-app web.dev memcached.dev cassandra.dev elastic.dev oltp.dev datamart.dev ods.dev session.dev quartz.dev job.dev etl-quartz.dev finex.dev   # VAGRANT ID: 8738cfc2-1f89-4d64-a225-4812f4528606
for host in dev-app web.dev memcached.dev cassandra.dev elastic.dev oltp.dev datamart.dev ods.dev session.dev quartz.dev job.dev etl-quartz.dev finex.dev; do time resolveip $host; done

IP address of dev-app is 192.168.56.3
real    0m0.017s

IP address of web.dev is 192.168.56.3
real    0m35.003s

IP address of memcached.dev is 192.168.56.3
real    0m35.004s

IP address of cassandra.dev is 192.168.56.3
real    0m0.008s

IP address of elastic.dev is 192.168.56.3
real    0m0.003s

[... the rest are .003s or .004s ...]

Note how most resolve as expected, but a few of them took 35 seconds...

move any two of the above aliases to a new line...

192.168.56.3    dev-app web.dev memcached.dev cassandra.dev elastic.dev oltp.dev datamart.dev ods.dev session.dev quartz.dev job.dev etl-quartz.dev     # VAGRANT ID: 8738cfc2-1f89-4d64-a225-4812f4528606
192.168.56.3    etl-quartz.dev finex.dev

and presto!

for host in dev-app web.dev memcached.dev cassandra.dev elastic.dev oltp.dev datamart.dev ods.dev session.dev quartz.dev job.dev etl-quartz.dev finex.dev; do time resolveip $host; done

IP address of dev-app is 192.168.56.3
real    0m0.003s

IP address of web.dev is 192.168.56.3
real    0m0.003s

IP address of memcached.dev is 192.168.56.3
real    0m0.003s

IP address of cassandra.dev is 192.168.56.3
real    0m0.003s

[... the rest are .003s ...]

Note: if you're using an old version of hostmanager, you can use this one-liner for sed to auto-split the lines:

awk '{if (NF>2 && match($(NF-2), /VAGRANT/)) for (i=2; i <= NF-4; i++) print $1 "\t" $(i) " # VAGRANT ID: " $NF; else print $0}' /etc/hosts > /etc/hosts
@dpehrson

This comment has been minimized.

dpehrson commented Apr 1, 2014

@delphyne Thanks for providing some more concrete evidence here.

With this said, can we get a thumbs up or down from maintainers to see whether this should in fact be fixed? One-host-per-line will work on all operating systems, the current setup makes the plugin very annoying to use on OSX.

@delphyne

This comment has been minimized.

delphyne commented Apr 10, 2014

as an update, this awk script will work for hostmanager 1.4's new format

/(vagrant-hostmanager-start|vagrant-hostmanager-end)/{f=f?0:1}f && /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]/ {
    if (NF>2) {
        out=""
        for (i=2;i<=NF;i++) { 
            out=(out $1 "\t" $(i) "\n")
        }
        $0=out
    }
}1
@pbitty

This comment has been minimized.

Contributor

pbitty commented Apr 26, 2014

I think this should be fixed if it's making life difficult for OSX users. It seems to me that the one-host-per-line would be the most straight-forward solution.

I've searched around and haven't found any indication of this causing issues on any of the major OSes. The closest discussion I found was this, but their main concern is overwriting reverse-lookup of 127.0.0.1. In our case, we're not using the localhost IP or name.

So I think it should be okay, and a pretty easy fix. @smdahlen, do you have any thoughts on this?

PS. Sorry for the delay in getting to this.

@paulcaskey

This comment has been minimized.

paulcaskey commented Aug 15, 2015

Something here is still messed up. I'm on OSX 10.9.5 and /etc/hosts basically stopped working at some point. I'm not sure when, but it's not due to these issues discussed here. (Many hostnames per line, which dang well SHOULD work, Apple! C'mon now! Why on earth would you mess with that?) (Nor entries only at the "top" of the file.)

I removed these comment lines and IPV6 entries at the top of my file, and now it works. I have no idea what was wrong in here. Maybe I disabled IPv6 on this laptop, and now those entries are invalid. Anyway Apple has clearly introduced many BUGS regarding /etc/hosts. Fix please! Sheesh! This stuff has worked since 1969! If it ain't broke, .. .. . .. !!!!

Paul

screenshot 2015-08-15 13 09 03

@brmendez

This comment has been minimized.

brmendez commented Oct 21, 2015

@dpehrson This worked. I also tried putting multiple hosts on one line and as you've stated. It does not work. Each host MUST be on it's own line.

Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment