Wednesday, May 10, 2006

Using HOSTS to block websites

I have to admit something: My name is Tim, and I'm a YouTube addict. Someone sent me a link to the Sony Bravia commercial (the one with with Jose González singing "Heartbeats") a few months ago and I haven't been able to get away from the site since. I'm powerless over it. My life has become unmanageable.

Which is all cool, the American way, really. Except when I started clicking into YouTube at work for a couple minutes, and had that turn into more than a couple minutes. This had to stop. I was going to have to call on a higher power.

I found it in the form of the HOSTS file. The HOSTS file is a simple way of bypassing the Domain Name Service (DNS) that converts Uniform Resource Locators (URLs) into IP addresses. Essentially, it acts like a telephone directory, remembering that "www.google.com" means "64.233.161.99" so you don't have to.

Because the DNS does such a great job, there isn't much call for the HOSTS file, unless you need to reach a site that only has an IP address (I used this hack recently as a workaround for some sloppy coding we got from a consultant), or if you want to redirect a troublesome URL to a safe one.

I bit the bullet and decided I was never going to look at YouTube at work again. So I opened c:/windows/system32/drivers/etc/HOSTS in notepad and put in the following entry, being careful not to erase anything that was already there:


# Sites I don't think I should look at at work
66.241.245.251 myspace.com
66.241.245.251 www.myspace.com
66.241.245.251 ebay.com
66.241.245.251 www.ebay.com
66.241.245.251 videosift.com
66.241.245.251 www.videosift.com
66.241.245.251 youtube.com
66.241.245.251 www.youtube.com

66.241.245.251 is the IP address of our company website (The Reinvestment Fund), but you could put whatever you want that is not problematic for you. I put in other potentially bothersome sites as well. Not that I look at eBay at work (really, boss, I don't). By the way, that big space there is a TAB. And the first line is a comment, because it starts with a pound sign.

The other thing I did to make my system a little more user friendly was to put a shortcut to "notepad c:\windows\system32\drivers\etc\HOSTS" on my desktop.

When I put a new entry into HOSTS, I may have to close my browser and run the command "ipconfig /flushdns" from the command line to make the change take effect.

"But Tim", you may say, "can't you just re-edit the HOSTS file and get back on youtube immediately?" Yep. But I haven't yet. Who knows why this works? Maybe it's the nature of this beast that I only indulge mindlessly, so when I have to become mindful to override the safefguard, I realize what I am doing and stop doing it.

No comments:

Post a Comment

I moderate comments blog posts over 14 days old. This keeps a lot of spam away. I generally am all right about moderating. Thanks for understanding.