Hoff MVP: blocking addiction sites in /etc/hosts
By Brenner Cruvinel • 2 minutes read
Cleaning up the Hoff repository, I found the very first proof of concept. The goal was to block pornography sites and the like for a close friend who was struggling with this addiction, which is silent and marginalized. It was the initial inspiration for everything. Finding it again was moving.
It is the rawest MVP possible: no app, just the hosts file. The idea is to point the domain to loopback, so the computer tries to open the site on itself and finds nothing. And what matters most is keeping the way back, to restore the file when the block needs to come off.
Blocking
Each line in /etc/hosts says "this name resolves to this address". To block, the address is the machine itself:
127.0.0.1 example.com
127.0.0.1 www.example.comYou need one line for each variation of the domain, with and without www. On macOS, after editing, it is worth flushing the DNS cache so the change takes effect right away:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderIt is an honest block, but a fragile one: anyone with the administrator password undoes it in seconds. Even so, it is one more bit of friction between the impulse and the click.
Restoring hosts on macOS
Overwrites /etc/hosts with the default macOS content:
sudo sh -c 'echo "##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
" > /etc/hosts'Restoring hosts on Windows
Open PowerShell as administrator. This command appends the localhost entries to the end of the file, without deleting the rest:
Start-Process powershell -Verb runAs -ArgumentList "Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value '127.0.0.1 localhost', '::1 localhost'"To really remove the block, you need to overwrite the whole file, not just append:
Start-Process powershell -Verb runAs -ArgumentList "Set-Content -Path C:\Windows\System32\drivers\etc\hosts -Value '127.0.0.1 localhost`n::1 localhost'"