Helping people with computers... one answer at a time.

There are ways to block URLs in IE, but doing so will block them from all other programs as well.

Is there a way to block certain URL's in IE?

Actually, there is, yes. But when you do it, you'll be blocking them in IE and any other program that might attempt to access them.

Interestingly enough, it's the same technique that some viruses use to block you from getting to anti-virus sites.

Normally Windows uses what's called DNS to map a domain name, such as "" to an IP address, like "". It's easier for you and me to remember domain names, and this also allows the domain name owners to change their internet addresses at will.

The "hosts" file is a plain text file that can contain overrides to DNS. In it you can hard-code the IP addresses that domain names will map to. Normally, it's not used at all, but it's a great opportunity to block access to domains you don't want accidental access to.

The hosts file is typically found in "c:\windows\system32\drivers\etc\hosts". You may need to change the file's read-only attribute so that you can make changes. Open it in notepad.

You should notice an entry like this: localhost

That defines the IP address of "localhost" to be, which by definition is your own machine.

To block a site, just add a similar entry to the end of the file. For example:

Now "" is mapped to your machine. Since you're probably not running a web server, any attempt to visit that site using a browser will fail. In fact, ANY attempt to use "" will get directed to your own machine and will typically fail.

The only caveat is that addresses are often cached by the software. That means you may need to exit all instances of your browser, for example, before the blockage becomes apparent. In the worst case, reboot, and it should take effect.

By the way, if you open the hosts file and find a long list of what look like anti-virus site domains, you've been infected by a virus and probably want to scan as soon as possible. And feel free to delete those entries from the file.

Article C2110 - July 10, 2004 « »

Share this article with your friends:

Share this article on Facebook Tweet this article Email a link to this article
Leo Leo A. Notenboom has been playing with computers since he was required to take a programming class in 1976. An 18 year career as a programmer at Microsoft soon followed. After "retiring" in 2001, Leo started Ask Leo! in 2003 as a place for answers to common computer and technical questions. More about Leo.

Not what you needed?

Jim Hicks
July 15, 2004 10:54 AM

The Hosts file can also be used to create nicknames for links. In my Hosts file I've added entries for the IPs to our HTML enabled hardware (like the networked printers) along with their short names; ex.
123.456.789.000 XYZ1 #Laser Printer
So if I need to check out the XYZ1 printer I can simply type "XYZ1" in my browser address bar and the Hosts file redirects me to the correct IP and opens up it's HTML maintenance screen.

October 6, 2004 3:04 AM

how can i stop downloading from a particular url atomatically?

April 8, 2005 9:28 PM

too much sites are blocked. Whenever I try to access "Required URL is not allowed". Is there any way I can pass through it?.

May 14, 2005 3:05 AM

not sure about this, but would it not be faster to use "" ? (the method is also very annoying when running a webserver)

July 20, 2005 5:00 AM

i want to prevent some email from sending to my hotmail email

my email
[Email Address Removed]

December 4, 2005 3:12 AM

i want to block passport network because i cant go on my msn...okay thankx

December 15, 2005 8:36 PM

No, you don't. Blocking passport will prevent you from being able to log in. This article has more:

December 19, 2005 7:44 AM

I dunno what happened. Recently, I cannot log into pages such as and

Also, I cannot get into any microsoft pages and cannot login to my MSN Messenger.

Would you by any chance know what is going on?

Leo A. Notenboom
December 19, 2005 10:52 AM

My first guess is spyware or virses. Do an up to date scan for both.

December 27, 2005 3:15 AM

Is there anyway can download block porn sex and leave in all the time and don't delete. For example I was looking for a house in the closure after that they send me porn sex in my computer. How they do that? I did not order anything about porn.
Thank You

Leo A. Notenboom
December 27, 2005 10:17 AM

I'm not quite sure what you you are asking, but I'm going to guess that you need to run anti-spyware software or implement an anti-spam solution

January 24, 2006 10:41 AM

I found the problem. Alot of the newer spyware removal tools use these things you have mentioned. In my HOSTS file there it was. Somehow entries had gotten int here by the spyware/adware or maybe even from a popup, I'm not sure. Anyway in my HOSTS there were a TON of entries like: xunleashed google


Removing those and rebooting fixed me up!

January 27, 2006 7:20 PM

Hi Leo, I've been having a (virus) problem with my computer that doesn't allow me to access, is there any method (or program) that could fix the problem?

February 25, 2006 8:26 AM

I am unable to block this URL ( by using the method you described above.

Any ideas why this would fail?

Here are the entries that I have tried:

February 25, 2006 9:32 AM

Ah. I see I chose a bad title for this article.

You can only block entire domains this way. So all of what you have will not work, as you've seen. However this:

would block all of

Think "no slashes" when adding entries to hosts.

kuldip Rathod
March 11, 2006 10:11 AM

How we can block cretain url using coding in

Is it compussory to make entry in the file
of every client machine or make one time entry in server machine

March 18, 2006 5:59 AM

I have got this problem recently, well i cant log into ebay, msn messneger, or hotmail, and even my bank, but when i look in the hosts i have a lot of anti virus sites listed, but they're still accesable, and i cant find or anything similar. Should i delete the hosts anyway, thanks a lot ive been trying to figure this out all day

May 3, 2006 8:42 PM

Can i do this for many websites? because my brother keeps watching porn... If i can, then how?

May 6, 2006 2:05 PM

hey, i have problems logging into yahoo, my bank, and places that require a username and a password. i dont know why its doing this! What's wrong?

May 22, 2006 8:33 PM

How can i block myspace from my computer?

May 22, 2006 8:52 PM

Follow the instructions in the article you just commented on :-).

June 26, 2006 8:42 AM

How can I block I followed the directions above but it seems that is not blockable.


Win Rodri
July 2, 2006 9:01 AM

I tried adding a list at the end. but the site was not blocked...what do i do...
ex :

plz do help

aayan patra
July 31, 2006 10:04 PM

I have two systems. One of them is fixed by the above solution but in my other system i couldn't find the "c:\windows\system32\drivers\etc\hosts". As the folder "system32" itself is not there. i have windows XP SP2 installed. Could you kindly guide me with asolution.

Leo Notenboom
July 31, 2006 10:09 PM

if you're using Windows Explorer to locate the file, make sure that it's configured to show system and hidden files. This article happens to show how to set that (in addition to a couple of other things:

August 21, 2006 11:00 PM

i tried deleting the anti virus sites in my hosts file but it wouldnt let me. the computer kept saving the deleted version as another file and would not let me overwrite the hosts file, i think i am missing somthing plz help this sucks!!

August 29, 2006 11:37 AM

Thank you man . this solved my problem with virus

August 30, 2006 3:54 PM

Thank You! I can now block that virus pit from my son's computer. Everytime he was on that site for more than ten minutes there would inevitably be a virus warning. I was getting tired of cleaning up after it.

September 11, 2006 7:05 PM

Hi, could you please tell me how to block a URL on a Mac? Thanks,

September 15, 2006 11:56 AM

Is there a way to do the opposite? To allow only one site and block all others without manually typing in every one to block?

Leo Notenboom
September 15, 2006 5:03 PM

Mac: I believe the file is the same, only located in /etc and called either hosts or localhosts.

September 27, 2006 3:44 AM

I cannot use hotmail via the internet explorer but I can if i go thru AOL. How do I fix that? Thanks

October 11, 2006 10:40 AM

Thank you so much, really helped with my virus problem (sites blocked that I had no idea about).

October 12, 2006 5:09 PM

i'm trying to block myspace but i can't find the IP address... what am i doing wrong? or at least how do i find it?

October 15, 2006 12:17 PM

The hosts file is typically found in "c:\windows\system32\drivers\etc\hosts". You may need to change the file's read-only attribute so that you can make changes. Open it in notepad.

But I found when I did this and only find the host file is 1k and cant' open it, please tell me how to open it in notepad, Thanks.

October 16, 2006 12:15 PM

I've followed all the instructions in the article but it still won't block the websites. :-( Is this specific for IE? I use Firefox but from what I understand, that wouldn't make much of a difference, would it?

October 27, 2006 3:37 AM

I have checked c:\windows\system32\drivers\etc\hosts and it is clean however I cannot access my website from 4 different computers one of which is not networked. This denial took place progressivly over 2 days and I suspect malicious code has been installed somwhere. Any idea where to look next.

November 7, 2006 11:43 AM

How do we open a block URL? I am working in Gulf & They block most of the site.

ms Alvs
November 14, 2006 4:35 AM

it blocks the parent url correct? meaning i should expect both and to be blocked under this right?

Leo Notenboom
November 14, 2006 8:38 AM


But remember that you probably need to block both "" and ""

November 15, 2006 2:31 PM

I've done everything as instructed, tried both "" and "", rebooted the machine, etc - the website is still as accessible as ever. Any more advice?

Oh, also there are many entries in the system32 hosts document but they aren't (to my limited knowledge) exclusively antivirus sites. For example "" and "".

Many Thanks.

November 17, 2006 1:25 PM

I added the lines:

They did nothing?!? why's that?

December 17, 2006 3:37 PM

I found a similar website instructing how to use the HOST page to block websites, but this one says to use the next # in the sequence. like and so on down through the numbers. one for each site requested to block.

is this necessary or can they all be listed under

Leo Notenboom
December 21, 2006 12:41 PM

I actually don't know why you'd want different numbers .. unless you were trying to trace things somehow. Setting them all to is just fine.

January 13, 2007 12:33 PM

I have noticed that some sites dont get blocked because they use subdomains that actually use a different IP address, so I ping the subdomain, then block that ip address instead of the domain.

January 25, 2007 6:33 PM

how can i overwrite hosts file??? it seems that its not overwritable when i changed something and save it as the same filename???

February 11, 2007 10:55 PM

there are two problems...
1. I did as u suggested but its not blocking any site.
2. What to do to allow a few sites and block all others.
will it be possible for you to answer me thru mail please.

March 4, 2007 3:19 AM

Great I use this often. I'd checked this out when I was 12 years old.

March 8, 2007 6:16 PM

is there a way to block all site except for mail servers? like tnx in advance

April 3, 2007 12:54 PM

If I create an entry in the Host file to send back to the loopback address will it work on all the portions of the website? Meaning, if I link to or type in (My former band) will it skip past the Host file entry since it just says and allow access to the page?

Leo A. Notenboom
April 4, 2007 2:18 PM

Hash: SHA1

You need two entries in hosts:

The key is that "" and "" are two different web
domains. Since they both get you to the same place you need to deal with both
of them.

What *follows* the "" doesn't matter.

Version: GnuPG v1.4.6 (MingW32)


April 11, 2007 10:51 PM

if you want to block and unblock websites plz go to and put words " Arm Aduld Filter 1.0 freeware " and click and you will find freeware software and download it free and use it.

April 23, 2007 7:26 AM

Thanx for help with restricting sites in IE...btw: my name is also Leo... :)

May 1, 2007 8:57 AM

I cant seem to make it work either. I rebooted and cleared the cache and such...

June 3, 2007 9:57 AM

Hey this is so cool! I just blocked that very annoying poker ad on the side of bitComet.

June 28, 2007 12:17 PM

And how would i unblock certain URL's?
im confused

July 1, 2007 2:03 PM

this **** sucks it does not work 100% what the hell is wrong with this host file, in all serious I'm frustrated to DEATH. half the sites are still unblocked.

# Copyright (c) 1993-1999 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# # source server
# # x client host localhost

July 30, 2007 2:44 AM

Hey Thanks for the useful info.

August 4, 2007 1:59 AM

This dosen't work. I have tried. Whats the prob ?

August 7, 2007 6:05 AM

You have probably set your browser to not check for new versions of the page every time, thus it uses whatever is in your cache, in temporary internet files. Clear your temporary internet files, or change that setting to check for new version everytime.

Tools > Internet Options > General tab - Browsing history > Settings > pick "Every time I visit the page"

a guy
August 10, 2007 8:52 AM

the guardware's iShield / iShield Plus is very good. try it out

September 16, 2007 5:25 PM

Here is how to do it right, look closely at the incrementation of every line: localhost

tranika williams
October 11, 2007 8:03 AM

thank u

November 2, 2007 2:06 PM

Oh! Windows defender keeps saying that the host file have been changed, and i can see lots of bad names. BUT IS IT FOR BLOCKING??? because i deny them all the time

November 26, 2007 10:24 PM

It is a good idea. Thanks

November 29, 2007 6:38 AM

great but how to i get to this..c:\windows\system32\drivers\etc\hosts

ed m
December 27, 2007 12:48 PM

Works fine for me!!!!

I added and

Now when I go to, my browser clicks about 6 times after initial pageload, but the little "advertisment" square in middle/right part of screen IS BLANK!!!!!!!!!!!!!!!!!

January 3, 2008 10:05 AM

ok nice.! but.
how if the donain has sub domains.
eg blocked but they have subdomain

ok i coud put that name to the list but the domain coud have hundred of sub names and building up new ones.

so is ther a wildcard i coud use or something.

tryed * and but no luck.

Helo Pilot
January 21, 2008 6:49 PM

This isn't URL blocking. A URL refers to a complete host name/file name pairing. What you describe is properly referred to as HOST blocking. If I wanted to block ONE PAGE or more likely a SCRIPT from a host (a URL) - I could not do it using the HOSTS file and leave the rest of the site open.

Leo A. Notenboom
January 22, 2008 6:02 PM

Hash: SHA1

I sit corrected - you're quite right.


Version: GnuPG v1.4.7 (MingW32)


February 2, 2008 3:15 AM

please help. my bf keeps screwing around with settings and what not on my comp. My internet works good enough for me but when i click on hotmail on the msn homepage to get to my email as usual, it just goes to a blank white page and does nothing.a long address goes into my address bar and thats it.nothing.if someone knows how i can fix this, please let me know somehow. Im not sure of who im even writing this to.?please.

February 8, 2008 12:26 AM

i tried blocking some sites on the hosts on my computer but it didnt work.i restart my computer but still i can access to that site?why is that?is there any other way to block sites aside blocking them on the host?thanks

sudhanshu tooteja
March 5, 2008 10:50 AM

I ahve been trying the above method but it didint work there are number of escape route. Can you tell me how to block all the instances of the web page

March 12, 2008 2:17 PM

This Solution works I promise I recently Applied it to my computer to keep my daughter off Remember you have to line it up exactly as it appears in the host file EX. I promise you this works. Now the only thing is It does not block you from putting the IP adress in to the run slot to overide. this is the only way around this once you add this site to the host file. If your child is not a computer geek there is no way around it.

March 28, 2008 3:32 PM

hey thanks alot for the help i am using this to try and stop CID: pop-ups firstly i this the correct thing to do secondly will itblock all the CID: pop-ups?

May 3, 2008 2:01 PM

how can I block my kids from accessing myspace and all it's subcomponients from my computer, ie., etc.

June 17, 2008 11:01 PM

I am able to get into my mail address but not able to read anything as it wont let me readd into
any of my inbox,draft,sent etc.
i just get the pop up saying comp had encountered a problem and given a choice to send report or not.
after clicking on any, then i looses my site and have to try to log in again...
Please help

Dennis Gamara
July 11, 2008 9:37 AM

Good Day,

Is there a way that you can block all the URL and allow a certain website only ?

Thank You
-- dennis

anonymous guy
July 18, 2008 6:51 PM

this method pretty much works, but only providing that the end user isn't that innept in the innards of "stuff that is crammed in the computer". Since there are WAYS to get around this.

A more appropriate solution would be to either: write, or find someone that does programming and have them write it for you, that does something similiar *like* this, but a little bit more advanced that involves packet sniffing techniques and does a stealth comparision test on the information passing through the TCP/IP connection. You simply strip out a section of the packets then reassemble them into a string, then test that string against an existing datafile that you specify (either a host, or a specific url). If found then add a section of code that locates the current active window handle (parent handle-your browser), then locates the control handle for url addresses typed or entered, then send a faked click hit on the goto button or whatever its control is labeled or handle is known as. Works great at catching personnel wasting company time & money. This method works down at the hardware level since its capturing raw packets which the browser doesn't control nor see. But all this needs to be done in stealth, or it can be defeated as well. This might be a little bit more than most people could take on as a small project, so either look for something that is already existing and written, or find you a programmer that takes on simple stuff like this and have them write it for you. And sorry, no, i won't write this for you. I've already got ALOT more than what I can handle at the moment as projects goes.

August 19, 2008 10:22 PM

Leo, your solution did not work at all. I can still access the site in question :(

I open the host in notepad, find where it says localhost, then make a new line and type in saves and exits. But I still can access the site! Please help :(

September 3, 2008 2:30 AM

with my IE 7.0 it still can acces the site.
diffrent with my firefox 3.0 it can't
My Question is is this for IE article or for the others browser also. TQ

But Thx for the tips.

September 17, 2008 12:15 AM

Make sure that you're NOT entering

but that you ARE entering

In fact, to be safe(r), might wanna make it
September 30, 2008 3:41 PM

Thanks,this really helps.

October 7, 2008 6:28 AM

I think someone is blocking me from being on popular site called Is this possible to block my ip address from the whole tribe network???

November 22, 2008 10:56 PM

Dear brothers;

i need help , i am working in a bank, in afghanistan, any site i am entering is blocked , i am tired of it, is there any way to access the websites that are blocked by the servers.

[personal address removed]

my email write me the solution plz.


December 4, 2008 11:57 PM

how do I change the read only attributes when I try to save it, it says that it cannot and to make sure the path and file name are correct please help me.

Michael Freidgeim
December 6, 2008 3:17 AM

Is it possible to block soem pages , but not whole site?
E.g block domain/badPage.htm but leave allowed domain/GoodPage.htm?

Not easily, no.
- Leo

January 20, 2009 6:04 PM

I keep getting some unwanted e-mails ,I keep blocking and deleting these mails and addrreses. But I noticed that everytime they use a new address , is there anything I can do about this.


That's the definition of SPAM. Try this article: How do I get rid of all this spam?!?!
- Leo
August 4, 2009 1:25 AM

whenever i try to save the file it windows says it cannot create the file, and to make sure the path and file name are correct, i checked, both were.

i also checked to make sure that it wasnt read only, and it was not, so im not sure of the problem.


September 20, 2009 12:05 AM

Leo is perfectly correct all he has said here. But who are saying its not working make sure you typed (spance here)
Without space it won't work.

And the message it cannot create the file, and to make sure the path and file name are correct: is shown because the file hosts is being accessed by another process (may be your antivirus). If so then first disable antivirus then try to change the file again. Hope, you'll able to do this time.

But Leo I need a little bit more expand with that. Suppose I want to redirect all subdomains of the site e.g,, etc. Then without writing all these can I do this just by this kind of trick: *

Another issue: If someone tries with the ip address of the he can easily enter the site because we are redirecting during domain name to ip conversion processing. What is solution if I also want to redirect if someone tries with the ip address of the site.

Thanks leo very much.
Thanks Leo.

My understanding is that wildcards (*) do not work in the hosts file.

For sites that have dedicated servers, there's no way to block direct-IP address. The good news is that many sites are on shared hosting, which means that an IP address alone is not enough. More here: Why doesn't accessing a site by its IP address work?


September 21, 2009 9:25 PM

# Copyright (c) 1993-1999 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# # source server
# # x client host localhost
here my file but I don't see the site that I want to block.

Also this started because whenever I try and goto a particular site it loads it for a second and then redirects me here which I am hoping if I block it will stop this nasty little redirection. Any other assistance would be gratefully accepted. Thanks

September 21, 2009 9:26 PM
I am adding this post as the web address above didn't show up. trying again

December 2, 2009 8:15 PM

I am trying to block craigslist from my children on my computer, I tried the and added craigslist to the end of the all 3 ways ",,craiglist" but using google search I am still able to get to the website.please help-how can I block this website when using google,msn or anyother search engine.

December 13, 2009 12:40 PM

I having problems with going to youtube everytime i go to the website it is overtaken by another is the website that is replacing it and i have no idea why.

May 13, 2010 4:28 PM

Is there a way to block a range of ip address's in IE 8

October 3, 2010 11:42 AM

I,m having problems with my hotmail account....i,m starting 2 received strange mails from adult sites that I have never been before and they just won,t stop!!! I don,t know if someone played a joke on me with that but I want them OUT OF MY MAIL

harry s.
November 24, 2010 9:25 AM can just use a web filter..e.g.: homeguard:

stop husky digging
February 2, 2011 2:17 PM

Your navagination bar is stretching the page out ,but this only happens in chrome. In firefox it looks alright though.. At first I thought that it was just something wrong with my browser. Just letting you know so you can fix it :)

I'm not seeing it - in Chrome, Firefox or IE. Are you sure you're not viewing with a zoomed setting?

February 23, 2011 8:08 AM

Actually, editing hosts file affects all web browsers, not only IE. So if you want to block some adresses only in IE, you should use some other way.

art thesis

Shan Moores
August 8, 2011 6:36 PM

Thanks a lot for the blog article.Really thank you! Much obliged.

September 22, 2011 12:09 PM

Dear Leo, beautiful Yr website & thanks for yr help!!
I’ve been reading all of 102 posts, but still could you explane something better about:
1) if we find written " localhost", shall we delete the word "localhost" or let it there and simply to write addresses after that?
2) In my host file I’ve found this (se below): what the 2nd line is? Since I have many troubles like entering in my HotMail account, ecc., could it be a virus harassing my computer? Or could it be something created by a IP changer program, ad Jdownloader? Anyway, should I delete it or not?

# localhost name resolution is handled within DNS itself.
# localhost
# ::1 localhost

3) What happen if we delete “” and write instead “”, or similar? Is this a way to get a new IP? Does it works?
I HOPE YOU’LL REPLY. If not, replies from other helpers are welcome, too! Venetian girl :) God bless you, Leo! ;)

1) simply add new entries after that line 2) that's the IP version 6 equivalent entry - is IP version 4. 3) No this has nothing to do with the IP address assigned to your machine by your network.

September 24, 2011 12:38 PM

Dear Leo, thanks so much for yr reply! I was afraid do not get it :) I've understood, thanks!
I made a mistake anyway, because yesterday I tried to create the automatic IP change of Jdownloader, but there was not info about how to go on with the process, so I stoped that and... since that moment my downloads with any download tood is SOOO slow, quite still! I think something ruined my connection/IP (I use a public wifi connection with my own comp)... Anyway, I'll find the solution, I hope...
Thank you so much for your free, friendly help :)

Ad Copy
April 14, 2012 12:54 AM

I just wanted to say I enjoyed your posting. Would you mind if I quote a few of these articles on my site as long as I provide credit and sources back to your blog? My website is in the exact same niche as this site and I'm sure my followers would truly benefit from some of the content and information you present here. Cheers!

That's this article already on the site: Can I republish your articles?
November 22, 2012 6:02 AM

i have entered my wrong password many times and my hotmail is closed so i can't open it now.
please help me , with thanks

November 22, 2012 9:51 AM

Try this article:
What are my Lost Hotmail Account and Password Recovery Options?

Comments on this entry are closed.

If you have a question, start by using the search box up at the top of the page - there's a very good chance that your question has already been answered on Ask Leo!.

If you don't find your answer, head out to to ask your question.