MacOS – /etc/hosts not working on macOS 10.13


I tried to use /etc/hosts file to redirect some websites to localhost.
To do so, I opened it in terminal using sudo nano /etc/hosts then I modified the file, and saved it. As the last step I flushed the DNS cache with sudo killall -HUP mDNSResponder.

Here's what my hosts file looks like:

$ cat /etc/hosts
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
## localhost broadcasthost
::1 localhost

This simply doesn't work. I tried to reboot, without luck. I also did a lot of research but did not find any working answers on the internet. Does the OS still use this file, or will this never really work?

I'm using macOS 10.13.

Best Answer

I had the hosts and IP addresses separated by tabs, switching to just one space between them worked for me: