How to block websites using the Hosts file
The hosts file can block websites or redirect websites. For Windows users:
Step 1 – Open Notepad – “Run as ADMIN”
You can’t save the hosts file, unless you have Admin rights…
Start > All Programs
Accessories > Notepad
Right Click Notpad > Run as Administrator
Yes
File Open
All Files **Bottom left of dialogue box**
Note how it defaults to .txt (bottom right hand corner), we need to change this to ALL FILES.
*****
Step 2 – Locate your Hosts file
Computer > C: Drive
Windows > System32 > drivers > etc >hosts
Open
Hosts file will open
Yay…. Here comes the fun bit.
********
Step 3 – How to block Google using the hosts file – with a www address.
Beware.. wordpress are making this a http:// address – all you need is the www website name. 🙂
127.0.0.1 http://www.google.com
127.0.01 http://www.google.co.uk
File
Save
******
Step 4 – Test the hosts file blocks http://www.google.co.uk
Close down your web browser and reopen it.
1. Try to go to http://www.google.co.uk – it should generate an error “Unable to connect”
How does this happen?
127.0.0.1 is a special IP – it’s a “virtual” or fake IP on your own laptop.
Therefore you’re redirecting http://www.google.co.uk into the ether of a virtual – or fake IP. Woohoo!!
*****
Step 5 – Hard code in IP numbers to site – to speed dial into websites
Just in case the DNS system ever fails (ie how to find websites), you can put the IP and website directly into the hosts file. If the DNS system fails – you can still access the sites hardcoded into your computer. Only you will be able to… and I’ve experienced the DNS servers at a telephone exchange failing… and I was the only person with Internet access for 2 weeks. So you’ll never know when this will be handy for you.
It makes your system DNS server fault tolerant.
It makes your web browsing of these sites much faster.
******
Step 6 – How do I find out the IP address of a web site?
Start > All Programs
Accessories > CMD Prompt
Type in “ping http://www.startpage.com” or “ping http://www.bbc.co.uk”
We can see from the reply that the IP for Startpage is 89.146.4.151.
So in the hosts file enter:
89.146.4.151 http://www.startpage.com
Step 7 – Temporarily block a site by using the hash symbol in the hosts file
You might want to block a site now and again… not permanently.
Place a hash # in front of the line in your hosts file – and it will be ignored. So….
#127.0.0.1 http://www.google.co.uk
will NOT work – as it’s got the hash at the start of the line. Remove the Hash and it then blocks Google. It’s like a little light switch turning the blocking on and off.
This can be used to block the DNS of your ISP for a short while.
*****
Now have some fun.
Add in all your favourite websites. Providing they have a static IP, you can now “speed dial” them an this will improve the speed of your browsing and your fault tolerance to DNS failures.
Did you get an error message?
If you see this – you haven’t opened Notepad with Admin rights.
It won’t allow you to save your hosts file.
*****
Also useful if the root DNS servers get tampered with, for whatever reason.
LikeLike
Hiya!
Yeah, I have speed dials to favourite web sites set up in the hosts files….
If the government wants to block access, they’ll mess up the DNS system. So having static IP numbers hand coded into the DNS means you can bypass this restriction. 🙂
Love it 🙂
LikeLike