Hacker News new | ask | show | jobs
by QuasiAlon 3160 days ago
Non techie here. Mind sharing what the hosts file is and how you use it? I've been hesitant to use 3rd party extensions/tools that block websites. I just assume if they are free they must sell my data. Also, controlling something on local machine could be cool. I'd experiment with adding/removing sites on random timeframes, to see if that could help me (one weird trick to help you overcome your social media addiction!)
2 comments

- on linux/osx its /etc/hosts

- on windows its c:\Windows\System32\Drivers\etc\hosts

If you add a line in it like

     0.0.0.0 reddit.com www.reddit.com
You tell the computer to use 0.0.0.0 (your own address) for those domains, and they subsequently won't load.
0.0.0.0 is the "any" address. Binding to it means you want to receive connections from all interfaces, sending datagrams to it means you want to broadcast to all hosts, and so on.
Note for Windows users: hosts file requires admin privileges to edit. So launch e.g. notepad as admin (launching as admin should be available if you right-click on the notepad icon), and go find the file. Also remember that you need to switch the dropdown to "All files (.)" in the Open File dialog.
Thank you very much for your reply. I magic barred it on my mac and couldn't find it. A little more help? Know the direct path? Is it global or per browser? Thanks again.
Those are the direct paths and it's system global.

BTW. 0.0.0.0 is not "your own IP", that would be 127.0.0.1. 0.0.0.0 is non-routable, so always resulting in error.

Strange. Neither sportlight or alfred can find it. (and alfred does search though system files)
The file name is just “hosts” and it’s located in a folder called “etc” - maybe that helps? I think there is also a macOS setting that hides certain system files. You may have to unhide it first.
Open terminal, type:

  cat /etc/hosts
if it outputs something that has to do with network, you know the file is there :). It might be that default user-facing tools on Mac don't look for system files?
A hosts file is like a phone directory stored on your computer that is accessed prior to going to DNS on the internet to search for the ip address for a website.

The experiment you speak of is something I've now run for the better part of a decade. Adding sites to the host files does make you forget, eventually.

If you add the following to the end of your hosts file,

127.0.0.1 Facebook.com

The above will redirect all requests to faceboom.com back to your own computer (the 127.0.0.1 part), instead of trying to search for Facebook's ip address and sending you there.

The hosts file is stored in different places on Mac vs windows, a quick search will get you going.