简体   繁体   English

"即使在杀死 mDNSResolver 之后,Mac OSX 更改 \/etc\/hosts 也没有效果"

[英]Mac OSX changing /etc/hosts has no effect even after killing mDNSResolver

I have not had a similar issue in Windows (10) and nothing I've searched on docs seems to indicate why, if this does not work, that that is the case我在 Windows (10) 中没有遇到类似的问题,而且我在文档上搜索的任何内容似乎都没有表明为什么,如果这不起作用,就是这种情况

  • I open up terminal and edit \/etc\/hosts (which I've done many times on a PC and a few years back on an OSX too)我打开终端并编辑 \/etc\/hosts (我在 PC 上做过很多次,几年前也在 OSX 上做过)<\/li>
  • Just for grins if that doesn't work I type in sudo killall -HUP mDNSResponder<\/code>如果这不起作用,我只是为了笑,我输入sudo killall -HUP mDNSResponder<\/code><\/li>
  • Then for more grins I reboot然后为了更多的笑容,我重新启动<\/li><\/ul>

    This has absolutely no effect.这完全没有效果。 Can anyone point me to why?谁能指出我为什么? Thanks.谢谢。


    UPDATE<\/strong> : The embarrassing fact of the matter is that the lines I entered in \/etc\/hosts<\/code> were in reverse, ie domain first, as:更新<\/strong>:这件事令人尴尬的事实是,我在\/etc\/hosts<\/code>中输入的行是相反的,即域优先,如:

     mydomain.com 192.168.33.10 #wrong 192.168.33.10 mydomain.com #what it should have been<\/code><\/pre>

    The accepted answer, however, is well-written and appreciated.然而,接受的答案写得很好,值得赞赏。

    "

I've seen two common problems with using /etc/hosts on macOS (/OS X):我发现在 macOS (/OS X) 上使用 /etc/hosts 有两个常见问题:

  • Incorrect formatting: each entry in the /etc/hosts file must be an IP address followed by a space or tab, followed by the name, then a linefeed at the end of the line.格式不正确:/etc/hosts 文件中的每个条目必须是一个 IP 地址,后跟一个空格或制表符,然后是名称,然后是行尾的换行符。 Try printing the hosts file with cat -vet /etc/hosts to make normally invisible characters visible.尝试使用 cat -vet /etc/hosts 打印主机文件以使通常不可见的字符可见。 Each line should look like one of these:每行应如下所示:

     127.0.0.1^Iwww.example.com$ 127.0.0.1 www.example.com$

    (The "^I" is a tab, and the "$" is the linefeed at the end of the line.) It's also ok if the entry has multiple names listed (also separated by spaces or tabs). (“^I”是制表符,“$”是行尾的换行符。)如果条目列出了多个名称(也用空格或制表符分隔),也可以。

    If you see a "^M" (carriage return) just before the "$", you have DOS/Windows formatted text and you need to remove the carriage return(s).如果您在“$”之前看到“^M”(回车),则您有 DOS/Windows 格式的文本,您需要删除回车。

  • Incorrect testing: Don't use the command-line tools dig , host , and nslookup , since they all test DNS directly and therefore bypass the /etc/hosts file.不正确的测试:不要使用命令行工具dighostnslookup ,因为它们都直接测试 DNS,因此绕过 /etc/hosts 文件。 Browsers sometimes cache things, which can give misleading results.浏览器有时会缓存内容,这可能会产生误导性的结果。 The "right" way to test the system's name resolution system is with the dscacheutil command:测试系统名称解析系统的“正确”方法是使用dscacheutil命令:

     dscacheutil -q host -a name www.example.com

    ...but since that's annoyingly verbose, I tend to just use ping , and see what address it says it's going to test. ...但由于这很烦人,我倾向于只使用ping ,然后查看它说要测试的地址。

I came across this thread to try and solve the same issue on macOS Catalina and was not successful.我遇到了这个线程,试图在 macOS Catalina 上解决同样的问题,但没有成功。 This is because macOS Catalina has another thing going;这是因为 macOS Catalina 有另一件事要做; it will only make changes in the hosts file effective if you change them as the root user (this is not done with the sudo command) !!如果您以 root 用户身份更改主机文件,它只会使主机文件中的更改生效(这不是使用 sudo 命令完成的)!!

By default there is not a root user on your system so here's a link with a step by step guide to do so: https://support.apple.com/en-us/HT204012默认情况下,您的系统上没有 root 用户,因此这里有一个包含逐步指南的链接: https : //support.apple.com/en-us/HT204012

then I was able to:然后我能够:

su
nano /etc/hosts

for more information: https://discussions.apple.com/thread/250805304更多信息: https : //discussions.apple.com/thread/250805304

Below steps worked for me以下步骤对我有用

  1. flushing DNS sudo killall -HUP mDNSResponder (or kill DNS in activity monitor and let it reload)刷新 DNS sudo killall -HUP mDNSResponder (或在活动监视器中杀死 DNS 并让它重新加载)

2.Changing read-write permissions of /etc/host file should be -rw-r--r-- .Use commands $ sudo chmod g+r /etc/hosts and $ sudo chmod o+r /etc/hosts 2.更改/etc/host文件的读写权限应该是-rw-r--r-- 使用命令$ sudo chmod g+r /etc/hosts和$ sudo chmod o+r /etc/hosts

  1. Adding entry u want to add in host file with ipxxx.xx.xx.com添加条目你想在主机文件中添加 ipxxx.xx.xx.com

  2. moved these 2 lines in the end 255.255.255.255 broadcasthost ::1 localhost Administrators-MacBook-Pro.local最后移动了这两行 255.255.255.255 broadcasthost ::1 localhost Administrators-MacBook-Pro.local

  3. Step 1 again再次执行第 1 步

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM