There’s no shortage of browser extensions you can use to stay productive by blocking distracting websites throughout the day. (Sorry Reddit, YouTube, and Facebook.) But are they really that effective at keeping you from doing the work you need to get done? If you don’t have much self-control, you can disable or uninstall the extensions, or switch to another browser to thwart your good intentions.
What I find even more effective — because it’s annoying to reset and it’s universal for any browser you use on your operating system — is to block websites using your system’s hosts file. When you edit your hosts file, you’re telling your system to use a particular IP address instead of whatever your DNS server resolves to when you type a URL into your browser’s address bar. So, instead of facebook.com sending you to 188.8.131.52 (or whatever Facebook’s IP is when you read this article), you can have your browser send yourself to your own computer — 127.0.0.1 — which loads a fat pile of nothing on your screen.
Editing your hosts file in Windows
First, you’ll want to navigate to the directory that contains your hosts file. It’s buried within your Windows folder at:
That’s a good thing, since this means you’ll probably forget where it is, and that’ll make it trickier for you to undo your changes when temptation strikes.
Once you’re in that folder, open up the hosts file using any text editor you want. If your operating system gives you grief about needing administrator access, or some other message that says it can’t edit the hosts file while it’s in use, you have a few options. You can run your favourite text editor as an administrator (right-click and select that option when you’re in the Windows Start menu), which could allow you to edit the file. You might also have to restart your computer and, when it boots back up, immediately navigate to the hosts file and pull it up. Don’t do anything else.
When you open up the hosts file, you’ll likely see something like this:
You’ll want to start adding entries below the final “#” character, and the syntax will look a little something like this:
Each domain you want to block should appear directly below the one before it. As for what you should enter for the website, I’ve found success adding both the www and non-www versions of the site on separate lines. That’s all you need; Don’t try to get specific with a URL like
facebook.com/messages/t/, which won’t work. You’re blocking entire domains, not pages.
Once you’re done making your blocking list, save the hosts file. In some cases, you’ll find that your blocking works right away — trying to load the site in your browser that you typed into the hosts file accomplishes nothing. Sometimes, you might have to reset your computer for your changes to take effect. If you’re still finding that the site works, even though it shouldn’t, you might want to add the site’s actual IP address as well as another entry, which you’ll find via a typical DNS lookup tool. In Facebook’s case, your line in your hosts file would look something like this:
If you’re still having trouble, you might have to switch browsers. Chrome might still allow you to access Google websites, for example, even though they’ll be blocked in Firefox or Edge.
Editing your hosts file in macOS
If you’re on a Mac, you’ll can pull up your hosts file by clicking on Go > Go to Folder and entering
/private/etc/hosts . Open it in a text editor and immediately attempt to save it. You’ll be asked to create a duplicate file, which you can dump on your desktop temporarily — don’t save it with the .txt extension, though.
Open the duplicate file and perform the same additions as before:
127.0.0.1 on each line, followed by whatever domains you want to block. Once you’ve made your additions, save the file and copy it from wherever it is you saved it back to
/private/etc/hosts , overwriting the original hosts file. If the websites you added aren’t immediately blocked, try flushing your DNS cache or restarting your Mac.