This post was published 5 years 4 months 17 days ago. Therefore, it may well be out of date. Do not reply on the contents of this post being accurate.
Back in February, I blogged about editing your Hosts file. The reason I used for doing this was to use your Hosts file to make it easier to log on to your networking hardware (router, modem, WAP, etc.).
Steve and Leo from Security Now podcast discuss the Hosts file in much greater detail in Episode 45.
Why would you want to mess around with your Hosts file?
Well, there’s the example in my previous post but Steve and Leo point out many more uses.
To start with every computer has one (well, at least all computers that use TCP/IP – the standard Internet protocol ‘glue’, as Steve puts it). Yep, Unix, Linux, Windows and Macs. It’s free and it can help you against the bad guys.
What does the Hosts file do?
The Hosts file performs the first DNS lookup that happens before any request goes out into the official DNS system across the Web. DNS systems match up IP addresses to domain names. So, when you type www.google.com into your browser, a DNS server converts this to the IP address of the right machine and bingo the right page is served (that’s rather simplistic but it’ll do for this purpose).
So what?
Well, as it’s the Hosts file that provides the very first DNS lookup you can change it to make your browsing more secure. A Steve puts it,
It can prevent a computer from going places you don’t want it too and, it’s simple to manage and maintain.
Steve’s info page for this podcast points to www.mvps.org which has more info on the Hosts file.
You can use your Hosts file to block ads, banners, 3rd party cookies, 3rd party page counters, web bugs, and even most hijackers. This is accomplished by blocking the connection(s) that supplies these little gems.
MVPS also includes a Hosts file you can freely use which currently lists about 11,700 sites to avoid.
Now includes most major parasites, hijackers and unwanted Search Engines!
If you run a web server on your machine you’d be better off using 0.0.0.0 instead of 127.0.0.1 (except for the very first entry which should read 127.0.0.1 localhost.
The easiest way to safely edit your Hosts file is as follows (NB. If you’re running a web server on the machine follow all steps – if you’re not running a web server you can miss out steps 3 – 6 if you wish):
- visit http://www.mvps.org/winhelp2002/hosts.txt
- select all the text (Ctrl A) then copy (Ctrl C)
- open Word and paste (Ctrl V) the text into Word
- Use Ctrl F to do a find and replace – find
127.0.0.1and replace with0.0.0.0 - Important – go back to the top of the doc and change the first line of code back to
127.0.0.1 localhost - Copy (Ctrl C) all of the text from your Word doc
- locate your Hosts file – see Steve’s directions
- open it in a Text editor – e.g. Windows users right-click and select Notepad
- select all (Ctrl A) then paste (Ctrl V) to replace the text with that which you created in Word
- click Save in Notepad to save your new Hosts file
- restart your computer
Here’s a copy of my Hosts file (as at the date of this post) which you can view in your browser (and also copy if you like but remember it’s probably been updated at MVPS by the time you’re reading this.
And here’s Wikipedia’s entry http://en.wikipedia.org/wiki/Hosts_file
[update - 25 09 2006] Mutant Matt has posted an article on how to edit your Hosts file on Mac OS X. Thanks Matt.