How to Block Distracting Sites With the Hosts File
There is no shortage of browser extensions that you can use to stay productive while blocking distracting websites throughout the day. (Sorry, Reddit, YouTube, and Facebook.) But are they really effective enough to keep you from getting the job done? If you have little self control, you can disable or uninstall extensions, or switch to another browser to thwart your good intentions.
What I find even more effective – because it gets boring to reset and is universal for whatever browser you use on your operating system – is blocking websites with your system’s hosts file. When you edit the hosts file, you are telling your system to use a specific IP address instead of what your DNS server allows when you enter the URL into your browser’s address bar. So instead of facebook.com sending you to 31.13.71.36 (or another Facebook IP as you read this article), you can set your browser to send to your own computer – 127.0.0.1 – which loads a huge a bunch of blank file to your screen.
Editing the hosts file in Windows
First you need to change to the directory containing your hosts file. It is buried in your Windows folder at: C:\Windows\System32\drivers\etc
This is good, as it means you are likely to forget where it is and it will be harder for you to undo the changes when tempted.
Once in this folder, open the hosts file using any text editor. If your operating system is upsetting you because of the need for administrator access or another message that says it cannot edit the hosts file while it is in use, you have several options. You can launch your favorite text editor as administrator (right-click and select this option when you are in the Windows Start menu), which will allow you to edit the file. You may also need to restart your computer and when it boots up immediately go to the hosts file and load it. Don’t do anything else.
When you open your hosts file, you will probably see something like this:
You will want to start adding entries under the last #, and the syntax is something like this:
127.0.0.1 facebook.com
Each domain you want to block should appear directly below the previous one . As for what you have to enter for the website, I have had success by adding the www and non-www versions of the site on separate lines. That’s all you need; Don’t try to concretize the url like facebook.com/messages/t/
, it won’t work. You are blocking entire domains, not pages.
When you’re done building your blocklist, save the hosts file. In some cases, you will find that your blocking is triggered immediately – trying to load the site in the browser that you entered in the hosts file does nothing. Sometimes you may need to restart your computer for the changes to take effect. If you still find the site is up and running, although it shouldn’t, you can add the site’s actual IP address, as well as another record that you find with your regular DNS lookup tool . In the case of Facebook, your line in your hosts file would look something like this:
127.0.0.1 31.13.90.36
If the problem persists, you may need to change your browser. Chrome may still allow you to access Google websites, for example, even if they are blocked in Firefox or Edge.
Editing the hosts file on macOS
If you’re on a Mac, you can upload the hosts file by clicking Go > Go to Folder and typing /private/etc/hosts
. Open it in a text editor and try saving right away. You will be prompted to create a duplicate of the file, which you can temporarily drop to your desktop, but do not save it with the .txt extension.
Open the duplicate file and do the same additions as before: 127.0.0.1
on each line, followed by any domains you want to block. After making your changes, save the file and copy it from wherever you saved it back to /private/etc/hosts
, overwriting the original hosts file. If the websites you added don’t block right away, try clearing your DNS cache or restarting your Mac.