2 0 1 1 年 1 0 月 2 9 日

Preventing procrastination with the hosts file


If you’re anything like me, you find that compulsively browsing around the web eats up a lot of your time every day. It’s not time well spent, and you could have achieved more if you’d resisted the urge.

A simple trick I use to cut down on this is to edit the hosts file. The hosts file is a list of websites and the IP addresses your computer should use to connect to them. You can use this to block websites by giving an incorrect IP address: your own.

This way, each time your computer tries to connect to a website on the list, it just gets looped backed round and stops. The page won’t load. This is great for blocking particular domains that seem to take up a lot of your time.

It’s a very quick, simple way to avoid procrastination.

Finding the hosts file

The hosts file is in different places on different operating systems.

On Linux, it’s at:

/etc/hosts

On Mac:

/private/etc/hosts

On Windows:

system32driversetchosts

These files need admin privileges to edit.

Blocking websites

Open the hosts file with a simple text editor. Make sure that the first line reads:

127.0.0.1    localhost

and make sure that it stays that way! To block websites, you just add a line with the domain after 127.0.0.1, e.g:

127.0.0.1 cracked.com

It’s probably a good idea to add a comment above the section of blocked domains to make it clear what they’re doing there. In the end you’ll have something like this:

# Anti-procrastination
127.0.0.1 cracked.com
127.0.0.1 crackedcdn.com
127.0.0.1 theonion.com
127.0.0.1 b3ta.com
127.0.0.1 tvtropes.org

(Be warned, these sites will waste a lot of your time if you give them the chance!)

It usually takes a minute or two for the changes to actually take effect. This is what makes the method work. You can of course easily edit the hosts file again to unblock domains, but this little barrier should be enough to discourage you. And, in the minute it takes for the changes to happen, you can probably focus on your work again.

Also, I’d strongly recommend blocking dodgy domains with the hosts file.