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
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
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.🙂
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”
So in the hosts file enter:
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….
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.