'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

  • 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)
  • Just for grins if that doesn't work I type in sudo killall -HUP mDNSResponder
  • Then for more grins I reboot

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


UPDATE: The embarrassing fact of the matter is that the lines I entered in /etc/hosts were in reverse, i.e. domain first, as:

mydomain.com  192.168.33.10    #wrong
192.168.33.10    mydomain.com  #what it should have been

The accepted answer, however, is well-written and appreciated.



Solution 1:[1]

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

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 simerbhatti