… that you don’t like. [See UPDATE at the end of this post]
Every PC has a facility within it that can stop your browser from taking you to sites you’d rather not visit (such as those hosting porn, scams, unwanted advertizing, whatever). It’s called the “hosts” file and once you understand how it works, it’s a fairly easy way to exert more control over your browsing experience.
You can find out about the hosts file (it has no extension – it’s not “hosts.txt” or “hosts.com”, but just “hosts”) online, or you can read a little here about the version used by Windows. There’s a version on the Mac and on any PC running any flavour/flavor of Linux, but for now I’m just going to outline the Windows version.
Its location varies slightly, depending on the version of Windows you’re using. I run XP Pro for my sins most of the time (I do run Linux but that’s a whole other blog), and so my hosts file sits in a folder called C:\Windows\System32\drivers\etc.
Generally speaking, it’s always in a folder called “etc”, even on other systems, if that helps you.
Its format is that of a plain text file – so never edit it with Word or indeed any other formatting-type editor. You can use Microsoft’s Notepad or, if you really know what you’re doing, any preferred plain text editor.
“So what?” you may ask.
Well, whenever your computer needs to access something on the Internet, it has to look it up, a bit like looking up someone’s telephone number when you want to call them.
Every site on the Internet – indeed, everything connected to the Internet, whether it is a site or not – is allocated what’s called an IP Address, a bit like a telephone number.
Currently the version in general use is called IPV4; there’s an IPV6 waiting in the wings that will need to be deployed soon. Just in case you were wondering.
You’re probably familiar with Internet addresses in the form “www.buildmeacastle.com”, but those are the versions that are helpful to humans.
Underlying that kind of address is another kind – the IP address. It’s a bit like a telephone number that’s unique to your machine at that moment in time (very important qualification), and it takes the form 123.222.123.012 – i.e., four groups of numbers separated by periods (or full stops if you prefer).
Each of those numbers can only take a value between 0 and 255, for reasons that are a little arcane to go into here (as if this wasn’t arcane enough already). Oh, all right, it’s because the number is a denary representation of an eight bit byte, and IPV4 is a four byte address system. Well, you did ask.
So the lowest address is 0.0.0.0 and the highest address is 255.255.255.255.
It’s possible for a single IP address to be mapped to multiple URLs, just to confuse matters.
Some IP addresses are reserved for special functions.
One is 0.0.0.0, which basically stands for “I don’t exist; go away and leave me in peace”. Another is 127.0.0.1, which refers to your machine (rather like saying “me”).
The hosts file consists of essentially a lookup table for IP addresses and their corresponding URLs. The format is straightforward; essentially each line in it looks like this:
We humans tend to regard websites and the like in terms of the URL (it’s easier for us to remember), but computers deal with the names in the form of IP addresses, so when we instruct our browser to go to a particular URL, the browser has to find out what IP address corresponds to that URL.
Its first port of call (one of several available to it) is your local hosts file.
In theory, you could fill up your hosts file with the IP adresses of your favorite/favourite URLs, but to be honest, there’s no real point. The file would be HUGE and take forever to search, so for all intents and purposes, the next port of call is used instead – the “domain name server”, which is a computer maintained by your Internet Service Provider (ISP). By and large you probably don’t know the details and there’s no real reason (most of the time) that you should.
So why am I talking about the local hosts file if there’s another machine perfectly capable of doing the job?
Here’s where things get a bit – well, shall we say sneaky?
Because your hosts file is the first port of call your browser uses, you can put the name (URL) of a website in there, but instead of providing the correct IP address for it, you can give instead either 127.0.0.1 or 0.0.0.0.
This has the effect of telling your browser that your machine is hosting the site in question.
Of course, your machine is doing no such thing. After a brief period of time (we’re talking milliseconds here), your browser will give up looking and come back to you with a “site not found” error message.
It turns out that using 0.0.0.0 instead of 127.0.0.1 provides a slightly quicker turnaround (even so, you’ll probably find that most sites on the Internet that talk about the hosts file suggest using 127.0.0.1), so your browsing experience is not slowed too much.
What this means is that if you create such a hosts file, and you then visit a web site that you DO want to look at, but it has ads on it that are linked to sites you DON’T want to visit (and which are probably putting or reading “cookies” on your system left, right, and centre, which I generally regard as an invasion of privacy), and you’ve got them listed in your hosts file, what you’ll see is a mishmash of little error messages in place of the ads (and no cookies, and no risk of adware, spyware, etc., being installed on your system).
Here’s a simple example of hosts in action on a Web page:
The embedded ad is replaced with an error message. If you’re curious as to what got blocked by hosts, you can find out easily enough.
Right click somewhere in the body text of the message (avoid anything that’s clearly a hyperlink) and from the resulting pop-up menu choose Properties:
The resulting Properties window will show you the site – in this case one of DoubleClick’s (the URL for the site’s address begins after the hash (#)):
There are some limitations. The current setup only works for the “top level” URL – so “www.nudeclogs.com” and not http://www.nudeclogs.com\bitsntums – so it’s a little sledgehammer-to-crack-an-egg, but in most cases you’ll not want to have any part of the offending (or offensive) website in the first place.
Other useful sites to block are those that try to find out where else you’ve been visiting – which apparently everyone who ever created a browser seems to think is an OK thing to do – so they can sell the information, along with your identification, to a bunch of other companies, and eventually your details end up in the hands of spammers and scammers, no matter how legitimate the purpose of the original website may have been.
There are sites online that maintain a huge list of other sites that are at best dubious and at worst downright criminal, and you can find them easily through search engines like Google.
I’ve used The Gorilla Design Studio‘s version of hosts as the starting point for my own but since it’s no longer updated, the MVPS site is the current go-to place, or you may choose to go another route.
The first line of your hosts file should ALWAYS be this:
In my hosts file I also have the IP addresses and names of other items in my network, such as my router and other computers, so that I get the quickest possible decision from my browser as it works out where it’s being asked to go.
Then everything underneath that is in this format:
and so on. You can comment out an entry for test purposes just by inserting a hash symbol (#) at the beginning of the line.
So is that it?
Well, not quite. The hosts file is loaded into your machine whenever it’s booted up, so making changes to the content will only have an impact if you then reboot. But who wants to keep doing that?
There is a shortcut, if you feel confident enough to try it.
First, open up a command line interface (this is really for Windows PC users only). Click Start, Run…, and then type the letters “cmd” into the white text box area and click OK. A small window will open.
Make sure the window is “active” (click somewhere in it first). Type the command “ipconfig /flushdns” with a space between the end of “ipconfig” and the forward slash, but no space between the forward slash and “flushdns”:
and then hit Enter.
A message should be generated that indicates the cache was flushed, which is computerese for “I just re-read your hosts file!”
To close this window simply type “exit”:
and hit Enter.
I won’t say “And that’s all there is to it!” but with time and practice you’ll eventually get the hang of it, and it’s such a useful thing to know.
At some point Microsoft must have patched Windows XP Pro because now, when you save the hosts file after making an edit, the (presumably) cached copy of hosts is updated automatically. So you don’t need to run ipconfig /flushdns separately. BFG