Technology in terms you understand. Sign up for the Confident Computing newsletter for weekly solutions to make your life easier. Click here and get The Ask Leo! Guide to Staying Safe on the Internet — FREE Edition as my thank you for subscribing!

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

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.

Become a Patron of Ask Leo! and go ad-free!

Normally Windows uses what’s called DNS to map a domain name, such as
“microsoft.com” to an IP address, like “207.46.130.108”. 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:

127.0.0.1 localhost

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

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

127.0.0.1 www.badsite.com

Now “www.badsite.com” 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 “www.badsite.com” 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.

Subscribe to Confident Computing! Tech problem solving & safety tips & a weekly confidence boost in your inbox every week.

I'll see you there!

10 Reasons Your Computer is Slow

Slow Computer?

Speed up with my special report: 10 Reasons Your Computer is Slow, now updated for Windows 10.

NOW: name your own price! You decide how much to pay -- and yes, that means you can get this report completely free if you so choose. Get your copy now!

106 comments on “Is there a way to block certain URL's in IE?”

  1. 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.

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

    Reply
  3. not sure about this, but would it not be faster to use “0.0.0.0 badsite.com” ? (the 127.0.0.1 method is also very annoying when running a webserver)

    Reply
  4. I dunno what happened. Recently, I cannot log into pages such as ebay.com and mail.yahoo.com

    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?
    Thx.

    Reply
  5. 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
    Jim

    Reply
  6. 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:

    127.0.0.1 http://www.xunleashed.com xunleashed.com xunleashed
    127.0.0.1 http://www.google.com google.com google

    etc.

    Removing those and rebooting fixed me up!

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

    Reply
  8. How we can block cretain url using coding in asp.net?

    Is it compussory to make entry in the file
    C:\windows\system32\drivers\etc\hosts
    of every client machine or make one time entry in server machine

    Reply
  9. 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 http://www.ebay.co.uk or anything similar. Should i delete the hosts anyway, thanks a lot ive been trying to figure this out all day

    Reply
  10. 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?

    Reply
  11. 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.

    Reply
  12. 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!!

    Reply
  13. Thank You! I can now block that virus pit myspace.com 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.

    Reply
  14. 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.

    Reply
  15. 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?

    Reply
  16. 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.

    Reply
  17. I’ve done everything as instructed, tried both “badsite.com” and “www.badsite.com”, 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 “www.mysearch.com” and “www.findology.mail.everyone.net”.

    Many Thanks.

    Reply
  18. I added the lines:

    127.0.0.1 servedby.advertising.com
    127.0.0.1 cdn.fastclick.net
    127.0.0.1 media.fastclick.net
    127.0.0.1 m.uk.2mdn.net

    They did nothing?!? why’s that?

    Reply
  19. 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 127.0.0.2 and so on down through the numbers. one for each site requested to block.

    is this necessary or can they all be listed under 127.0.0.1?

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

    Reply
  21. 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.

    Reply
  22. 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.
    thanks
    regards
    avi

    Reply
  23. —–BEGIN PGP SIGNED MESSAGE—–
    Hash: SHA1

    You need two entries in hosts:

    127.0.0.1 myspace.com
    127.0.0.1 http://www.myspace.com

    The key is that “myspace.com” and “www.myspace.com” 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 “myspace.com” doesn’t matter.

    Leo
    —–BEGIN PGP SIGNATURE—–
    Version: GnuPG v1.4.6 (MingW32)

    iD8DBQFGFBZuCMEe9B/8oqERAtRNAJ9V61C2GkjlQmaqfQQ2tFiozzKW7wCfVYMJ
    CPmwPwb14w6uWN17gtMB4kM=
    =+XYw
    —–END PGP SIGNATURE—–

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

    Reply
  25. 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:
    #
    #102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host

    127.0.0.1 localhost
    127.0.0.1 http://www.gaiaonline.com
    127.0.0.1 gaiaonline.com
    127.0.0.1 http://www.rs2cheating.com
    127.0.0.1 rs2cheating.com
    127.0.0.1 http://www.runescape.com
    127.0.0.1 runescape.com
    127.0.0.1 avatarsave.gaiaonline.com
    127.0.0.1 myspace.com
    127.0.0.1 http://www.myspace.com

    Reply
  26. 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”

    Reply
  27. 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

    Reply
  28. Works fine for me!!!!

    I added ad.doubleclick.com and ads.cnn.com.

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

    Reply
  29. ok nice.! but.
    how if the donain has sub domains.
    eg blocked badsite.com but they have subdomain adult.badsite.com

    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 *.badsite.com and #.badsite.com but no luck.

    Reply
  30. 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.

    Reply
  31. —–BEGIN PGP SIGNED MESSAGE—–
    Hash: SHA1

    I sit corrected – you’re quite right.

    Leo

    —–BEGIN PGP SIGNATURE—–
    Version: GnuPG v1.4.7 (MingW32)

    iD8DBQFHlqAyCMEe9B/8oqERAoaoAJ0VjBWk1cPUhHyrih/rWGxTQOTAKQCgjy8m
    W7+/fEtW7sw2gNxHsQfIVig=
    =6Lm3
    —–END PGP SIGNATURE—–

    Reply
  32. 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.

    Reply
  33. 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

    Reply
  34. This Solution works I promise I recently Applied it to my computer to keep my daughter off myspace.com. Remember you have to line it up exactly as it appears in the host file EX. 127.0.0.1 http://www.sitename.com. 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.

    Reply
  35. 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?

    Reply
  36. how can I block my kids from accessing myspace and all it’s subcomponients from my computer, ie. home.myspace.com/comment.myspace.com, etc.
    Thanks

    Reply
  37. 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

    Reply
  38. Good Day,

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

    Thank You
    — dennis

    Reply
  39. 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.

    Reply
  40. 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 127.0.0.1 localhost, then make a new line and type in 127.0.0.1 http://www.badsitesname.com saves and exits. But I still can access the site! Please help 🙁

    Reply
  41. 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.

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

    Reply
  43. 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.

    thanks

    Reply
  44. 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.

    Reply
  45. 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
    06-Dec-2008
    Reply
  46. 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.

    help?

    Reply
  47. Leo is perfectly correct all he has said here. But who are saying its not working make sure you typed 127.0.0.1 (spance here) http://www.badsitename.com.
    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 badsitename.com. e.g, blog.badsitename.com, http://www.badsitename.com. webmail.badsite.com etc. Then without writing all these can I do this just by this kind of trick:
    127.0.0.1 *.badsitename.com

    Another issue: If someone tries with the ip address of the badsitename.com 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?

    Leo
    20-Sep-2009

    Reply
  48. # 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:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host

    127.0.0.1 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

    Reply
  49. I am trying to block craigslist from my children on my computer, I tried the 127.0.0.1 and added craigslist to the end of the 127.0.0.1 all 3 ways “www.craigslist.org,craigslist.org,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.

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

    Reply
  51. 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?

    Leo
    02-Feb-2011

    Reply
  52. 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

    Reply
  53. 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 “127.0.0.1 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.
    # 127.0.0.1 localhost
    # ::1 localhost

    3) What happen if we delete “127.0.0.1” and write instead “127.0.0.2”, 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 – 127.0.0.1 is IP version 4. 3) No this has nothing to do with the IP address assigned to your machine by your network.

    Leo
    23-Sep-2011

    Reply
  54. 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 🙂

    Reply
  55. 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?

    Leo
    14-Apr-2012
    Reply

Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.