4

I have modified my /etc/hosts file to block website.com and www.website.com.

I know the formatting of my hosts file is correct because when I restart Safari, the block takes effect. I can also enter into a private window, and the block takes effect. If I do not take any action, Safari will eventually start blocking the sites from my host file after about 5 minutes. Is therany wayay I can expedite this?

When I test in Chrome, there is no need to restart Chrome, my blocks immediately start working.

I've attempted:

sudo killall -HUP mDNSResponder

and

sudo dscacheutil -flushcache

I've also read attempted all of the formatting suggestions on stack exchange for the etc/hosts file, but nothing seems to work. No matter what, Safari needs to be reset for the blocks to take place.

I would like for a solution that can be done programmatically (i.e. through a terminal command or some sort of script - not through some GUI application) so that I can package this in with my application.

  • 1
    What do you mean by "programmatically"? – nohillside Jan 31 at 19:31
  • Either via some sort of script or terminal command. – TrevDev Jan 31 at 19:32
  • If you found a solution, please add it as an Answer. Don't edit your origianal question and add it there. I've rolled back the question to the last version prior to your "Solution Edit" – Allan Feb 5 at 22:15
3

I've discovered that if I disconnect from wifi for about 10 seconds and then reconnect, that will force safari to read the hosts file correctly. Anyone know what type of data gets cleared when you disconnect and reconnect to wifi? Maybe that can guide me to a workaround.

You must log in to answer this question.

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