1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What is the hosts file?

Discussion in 'Software' started by eclayton, Jul 29, 2004.

  1. eclayton

    eclayton Sgt. Shorts-cough

    Can someone tell me what the hosts file is and does?
  2. Matacumbie

    Matacumbie Rocky Top


    Found this, let me know if you want the link for the long version.

    The short answer is that the Hosts file is like an address book. When you type an address like www.yahoo.com into your browser, the Hosts file is consulted to see if you have the IP address, or "telephone number," for that site. If you do, then your computer will "call it" and the site will open. If not, your computer will ask your ISP's (internet service provider) computer for the phone number before it can "call" that site. Most of the time, you do not have addresses in your "address book," because you have not put any there. Therefore, most of the time your computer asks for the IP address from your ISP to find sites.

    If you put ad server names into your Hosts file with your own computer's IP address, your computer will never be able to contact the ad server. It will try to, but it will be simply calling itself and get a "busy signal" of sorts. Your computer will then give up calling the ad server and no ads will be loaded, nor will any tracking take place. Your choices for blocking sites are not just limited to blocking ad servers. You may block sites that serve advertisements, sites that serve objectionable content, or any other site that you choose to block.

  3. eclayton

    eclayton Sgt. Shorts-cough

    Thanks, Matacumbie,

    So where is the Hosts file located?

    I wouldn't mind having that link either! :)
  4. Matacumbie

    Matacumbie Rocky Top

  5. acejones

    acejones A Different Title


    my hosts file is in C:\WINDOWS\system32\drivers\etc (posted mine, b/c i thought they were supposed to be in C:\WINDOWS\system32\drivers)

    oh yeah...windows xp
  6. Ken3

    Ken3 MajorGeek

    Eric - if I remember right you're using Win2000, so from Ace's post replace "windows" with "winnt" and there it is. You can also do a Find on "hosts" to get at it quicker.
  7. Maxwell

    Maxwell Folgers

  8. eclayton

    eclayton Sgt. Shorts-cough

    Wow, dude, you have a good memory! But, we just recently got XP! :D

    Okay, so, if I use the list that Nick posted, and I'm using Spyware blaster, do I just copy and paste those files in the hosts file section of Spyware Blaster? There are also some that are supposed to go into the restricted pages......seems I have my work cut out for me if I do this, but from the sounds of it, it's worth it......

    Do I have this right?
  9. Maxwell

    Maxwell Folgers

    I have SpywareBlaster version 3.2 but doesn't have a "hosts" section but it does have a means of backing up your hosts file. I usually just download and put the hosts file in place manually plus I protect it by making it read-only.
  10. eclayton

    eclayton Sgt. Shorts-cough

    Okay, that makes sense, but I'm still not sure how to edit my hosts file.

    Can someone walk me through it step by step?
  11. eclayton

    eclayton Sgt. Shorts-cough

    Well, maybe I figured this out.
    I opened the second link on Nicks post, downloaded the zip file, then copied it and pasted it over top of my old hosts file in C:Windows/system32/drivers/etc

    I hope that was right.......
  12. bigbazza

    bigbazza R.I.P. 14/12/2011 - Good Onya Geek

    ec, check out my post today in http://forums.majorgeeks.com/showthread.php?t=38366 in answer to laurieB's question on hosts file. Lots of old MG links there that expand on what is posted here. Beware laurieB 's post hijacked part way through. Look for my post today. bazza.


  13. Maxwell

    Maxwell Folgers

    Hang on Eric, did you already have a hosts file? What was in it? Did you keep a backup in case there was something significant in it? Occasionally you may have had some valid address translations in there to do with your e-mail client - see caveats at http://www.mvps.org/winhelp2002/hosts.htm

    However, the new hosts will protect you from adverts, etc.
  14. eclayton

    eclayton Sgt. Shorts-cough

    I don't think I had a hosts file, because I never made one. Anyway, it's done now! :( :)

    How do I go about adding the actual addresses of the sites that I want to browse faster? How do i find the number of the site, say, for Major Geeks?

    I appreciate everyone's help, I'm learning alot here, it's fun! :)
  15. da chicken

    da chicken MajorGeek

    Everyone has one. It's just a text file. You can actually just open it up with Notepad or another pure text editor (but not a word procesor like WordPad or MS Word).

    The default one looks like this:
    # 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:
    #     rhino.acme.com          # source server
    #     x.acme.com              # x client host       localhost
    Open up a command prompt (Start --> Run --> "cmd"). From here, type "nslookup <domain name>". So for www.majorgeeks.com, it will look like this:
    C:\>nslookup [url]www.majorgeeks.com[/url]
    Server:  you.dns.server.here.com
    Address:  xxx.xxx.xxx.xxx
    Non-authoritative answer:
    Name:    [url]www.majorgeeks.com[/url]
    The first part will look different, since I masked what my DNS server is. Now you go to Notepad and open up C:\winnt\system32\drivers\etc\hosts. Add the following line to the end of the file:

    Code: [url]www.majorgeeks.com[/url]
    Save the file and you're done. You don't have to reboot or anything.
  16. eclayton

    eclayton Sgt. Shorts-cough

    Very Cool! Thanks so much for the detailed info, it was easy to do. I went ahead and did it with MG, then went to do it with Yahoo......Yahoo has a few addresses. Do I need to enter each line seperately?
  17. da chicken

    da chicken MajorGeek

    Yes. You have to have a line break between each entry (i.e., only one per line), and there must be at least one space between the IP address and the domain name. Also, you can't use wildcards in a hosts file, so *.majorgeeks.com wouldn't be valid, even if www.majorgeeks.com and forums.majorgeeks.com were on the same server. (www.mg.c and forums.mg.c aren't even on the same network, so take note of that if you add both to your hosts file; they have different IP addresses

    ANHEDONIC Will Title For Food

    hmmm i'm confused... i thought peopel just edited their hosts file to block certain sites... what was the benefit of Eric adding the majorgeeks IP? :confused:

    my particular hosts file doesn't have any addy's but it was set to "read only" in properties...
  19. lesley

    lesley Private E-2

    Have read this post with great interest and I have located the hosts file on my C drive (am using windows CP home).

    When I opened the hosts file with notepad and added a URL (had obtained the nslookup details) and then went to save it, I had to save as a new file, did not save the file I had opened up. Does this mean that "nothing" is happening? Will my saved file override the original file or is the original file without my additional entry being used??

    thanks for your help
  20. da chicken

    da chicken MajorGeek

    Well, whenever you try to resolve a domain name, Windows checks the local DNS cache before anything else. There are two ways to get into the DNS cache: 1) be in the hosts file (a static cache), 2) be a domain name that was previously resolved this session (a dynamic cache).

    So, whenever a web browser or other piece of software requests DNS name resolution, it can find frequently used domain names in the dynamic or static cache. By default, the static cache only has the one entery for localhost, so the dynamic cache is the only one used.

    However, there's some problems with the dynamic cache. First, the size of the cache is limited. So eventually you'll start popping out old domains for new ones. Second, domain names not from the hosts file only stay in the cache for a set amount of time (known as a time-to-live) before being removed from the cache. Additionally, if you restart the system the dynamic cache automatically gets reset.

    The hosts file (static cache) doesn't have a fixed limit (and, to the best of my knowledge, doesn't take up any of the dynamic's size limit) and the entries never expire, so Windows never has to go out and ask the DNS server where www.google.com is, for example.

    There's a few problems with the hosts file, however. First, you have to edit the file manually. It's not automatic like the dynamic cache, so it requires a lot of user action to configure. Second, because it's static it doesn't take into account DNS changes. If the IP for www.google.com happens to change, for example, you will not be able to access that website until you manyally edit the hosts file again.

    Still, the hosts file does have a wide number of uses. because it can point to the wrong IP address, a lot of ad sites and spy sites can be added to hosts file and told to point to the IP address, a special IP address called the loopback (actually, it's any address with the first octect of 127). It always means "this machine". So if you point all these bad sites at the loopback IP, they go nowhere and just time out.

    However, there are also some types of malware that purposefully alter the hosts file. What if you put in an entry that pointed www.google.com to the Bonzi Buddy homepage? Therefore, a lot of spyware protection programs make the hosts file read-only to help prevent this kind of DNS cache poisoning.

    If you want to see the contents of the DNS cache, you can open up a command prompt and type "ipconfig /displaydns". You can empty the dynamic cache by entering "ipconfig /flushdns".

    On this page, scroll down to #2 and you'll see some registry hacks to improve the performance of the Windows dynamic DNS cache (but I've never used them so I can't exactly recommend it).

Share This Page

MajorGeeks.Com Menu

MajorGeeks.Com \ All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ NEW! PC Games \ System Tools \ Macintosh \ Demonews.Com \ Top Downloads

MajorGeeks.Com \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds