在Mac El Capitan(10.11.5)中忽略了/etc/hosts [英] /etc/hosts ignored in mac El Capitan (10.11.5)

查看:83
本文介绍了在Mac El Capitan(10.11.5)中忽略了/etc/hosts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将现有网址重定向到子网上的远程计算机.为此,我将以下内容放入/etc/hosts

I'm attempting to redirect an existing web address to a remote machine on my subnet. To do that, I put the following into /etc/hosts

192.168.1.249 holub.com

192.168.1.249 holub.com

并刷新DNS缓存

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder

但是,当我对holub.com进行ping操作时(我知道该地址如何真正解析的最可靠方式),我看到的是真实的网址(204.13.10.74),而不是/etc/hosts中指定的网址(192.168.1.249).有趣的是,mysqladmin实用程序不能正确解析地址,但是Chrome浏览器可以正确解析地址.我猜想Chrome有一些内部解决方法.

However, when I ping holub.com (the most reliable way that I know to see how the address is actually resolved), I see the real web address (204.13.10.74), not the one specified in /etc/hosts (192.168.1.249). Interestingly, the mysqladmin utility does not resolve the address correctly, but the Chrome browser does resolve the address correctly. I'm guessing that Chrome has some sort of internal workaround.

通常,看起来/etc/hosts是在实际DNS查找之后之后使用的,而不是应有的条件,因此外部地址是不可覆盖的.

In general, it looks like /etc/hosts is being used after the actual DNS lookup, not before as it should be, so an external address is not overridable.

我尝试使用各种等效于我本地地址的IPv6(0:0:0:0:0:ffff:c0a8:01f9 :: ffff:192.168.1.249 :: 192.168.1.249),但这不是帮助.重新引导(而不是刷新缓存)也无济于事.

I've tried using various IPv6 equivalents to my local address (0:0:0:0:0:ffff:c0a8:01f9 ::ffff:192.168.1.249 ::192.168.1.249), but that doesn't help. Rebooting (instead of flushing the cache) doesn't help either.

我发现了一种不令人满意的解决方法.如果我使用

I have found one unsatisfactory workaround. If I disable the DNS reponder with

sudo launchctl卸载-w/System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

然后使用了/etc/hosts,但是后来我无法访问互联网.

then /etc/hosts is used, but then I can't access the internet.

如果有人遇到此问题,我很想知道是否有解决方法.

If anybody's encountered this problem, I'd love to know if there's a workaround.

推荐答案

我在寻找类似问题的答案时碰到了这一点,并希望将我的发现发布给处于同一职位的其他人.

I came across this while searching for an answer to a similar problem and wanted to post my findings for anyone else in the same position.

以3人为一组,我们发现对我的/etc/hosts文件进行的编辑似乎起作用,而对其他两个主机文件的编辑似乎无效.经过进一步的挖掘,我们意识到我使用的是OS X 10.10,而它们使用的是较新版本.

As a team of three, we found that edits to my /etc/hosts file appeared to work, while editing the other two's host files seemingly did not. Upon further digging, we realized I was on OS X 10.10, while they were on newer versions.

经过一百万次尝试,我们发现在10.11及更高版本中对hosts文件的添加显然不能在IP与域之间形成一个以上的空间,例如:

We found, after trying about a million things, that additions to the hosts file in 10.11 and up apparently could not have more than one space between the IP and the domain, for example:

不起作用:

1.2.3.4     some.site.com

已完成工作:

1.2.3.4 some.site.com

进行此更改后,我们立即开始看到预期的结果,而没有任何缓存清除,重新启动或其他操作.

After making this change, we immediately started seeing expected results without any cache clears, reboots, or otherwise.

在您的示例中,我知道您仅显示一个空格,但是由于现在它正出现在实际文件中的可能性很小,所以我还是想共享它.

I know in your example you are only showing one space, but in the off chance that's now how it appeared in your actual file I wanted to share this anyway.

这篇关于在Mac El Capitan(10.11.5)中忽略了/etc/hosts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆