1

I need to test out a site before it's actually live for customers, and doing so with a specific hostname. For this I'd like to modify the well-known hosts file, however it doesnt seem to work.

An answer here mentions to do a copy of the file and modify, and then paste it back to the original /etc/hosts location. I've tried it but doesnt work.

I've tried the guide here too, with restarting the DNS services (sudo killall -HUP mDNSResponder) on my computer. Doesnt work either. I've made a complete reboot too, to no avail.

Have Apple prevented people in MacOS Catalina (10.15.X and later) to modify this file? It seems a lot of people are having problem with this.

Thanks for your help!

Update: To clarify: I can successfully change the hosts file and save it, but it seems to have no effect.

2
  • 2
    Please add the result of ls -la /etc/hosts. Then restore the original hosts file, add the line 127.0.0.1 google.xyz by editing the file with sudo nano /etc/hosts and finally enter ping google.xyz. Add the result to your question!
    – klanomath
    Apr 24, 2020 at 8:07
  • 1
    What does it doesn't seem to work mean? I copied a hosts file from github over that blocks ads/malware and it works just fine.
    – Bert
    Apr 24, 2020 at 12:14

3 Answers 3

3

What I did was sudo nano /private/etc/hosts and it worked.

2

So it actually did work.

What I did wrong (it seems) is that I had too many spaces between the ip and the hostname inside /etc/hosts. I fixed the spaces with the nano editor and now it works.

It's worth to point out that using nslookup will not work however to test your dns change (found reason here):

nslookup only does proper DNS resolution, which is significantly different from the Name Service Switch subsystem that your other applications use; that is to say nslookup ignores /etc/hosts and mDNS.

2

Gas Mask is an excellent app to manage your hosts file without using Terminal. I use it to quickly switch between different hosts files for different uses

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .