The View From Wisconsin

Just a random set of rants from a Sports Fan from Wisconsin.

Monday, October 26, 2009

The Hosts File And You

In a very odd way, I ended up returning to my Internet roots to solve a problem I'd wanted to solve for some time.

A little reveal here: I have had some issues with some websites on this big ol' place we call the Internet. (You can probably guess which ones; I'm not going to go into the details.) Now, for some time I've known that IE and most other browsers and internet apps access a file called "hosts" to map host names to IP addresses. Basically, if you type in some sort of shortcut in a web browser, it takes you to the list in the hosts file first before looking it up on the internet. The main use of this file nowadays is to use it to block websites at the core - basically, keeping you from even getting to the site at all.

I've used Spybot Search & Destroy to populate the Hosts file with blockable websites, and learned quickly to add my own as well. However, there was one thing I could not figure out: how to do it in the Mac OS.

I found out that there is a hosts file in OS X.4, located over in a hidden (from the Finder, at least) folder called /private/etc/. The Mac OS, however, is very very touchy about changing files like this, since anything in the OS's hidden files are password protected, as with most UNIX-type coding.

So I had to figure out how to get to that file and then edit it with a copy of the hosts file that I'd ported over to my Mac via my trusty thumb drive. It wasn't until I found some arcane coding tips that I discovered I could do it using an editor named "nano", which was part of the Mac application called... Terminal.

Terminal. Which was how I developed my first website on Exec-PC, about 16 years ago. And yes, it was back using the old Mac system 8. The app I used with Exec-PC, though, was something called pico... which was the editor that nano is based upon.

After a few starts and stops, I realized that I could use a UNIX code to edit the hosts file:

sudo nano /private/etc/hosts

By using the SUDO code, I could get around the password protection and save the thing, once I edited the file. And, with nano, I could simply copy and paste the hosts file list from my text file version to the hosts file on my Mac.

Nice and easy, right? Heh, WRONG. It wasn't that I couldn't do it - I did - it was that the file was 8,016 lines long. It took a good long chunk of time to get it all pasted; a little more than two hours, since nano could only post about one line per second. Once it was done, though, I saved it and cheered mightily.

Then came the fun of clearing the DNS cache. Took me a couple of stops and starts to do this in Terminal, but I got it done - and the blocking worked.