简体   繁体   中英

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

  • <\/li>
  • <\/li>
  • <\/li><\/ul>

    This has absolutely no effect. Can anyone point me to why? Thanks.


    "

I've seen two common problems with using /etc/hosts on macOS (/OS X):

  • 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. Try printing the hosts file with cat -vet /etc/hosts to make normally invisible characters visible. 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).

    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).

  • 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. 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 -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.

I came across this thread to try and solve the same issue on macOS Catalina and was not successful. This is because macOS Catalina has another thing going; 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) !!

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

then I was able to:

su
nano /etc/hosts

for more information: 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)

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

  1. Adding entry u want to add in host file with ipxxx.xx.xx.com

  2. moved these 2 lines in the end 255.255.255.255 broadcasthost ::1 localhost Administrators-MacBook-Pro.local

  3. Step 1 again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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