Using the HOSTS file - testmy.net resource / tool
Home
Welcome, Guest. Please login or register.
Did you miss your activation email?

 



donations help testmy.net pay for the very high cost to run the site. Any amount is greatly appreciated.
Click to read why...

  spcr
    
News : angel Do you think your good enough to write news for testmy.net?  Shoot me a PM and you may be accepted to write for us, a title of nobility Smile September 05, 2008, 08:55:20 AM
testmy.net Broadband  |  Main Forum  |  Guides  |  Topic: Using the HOSTS file Advanced search
  0 Members and 1 Guest are viewing this topic. « previous next »
Pages 1 Go Down
Author
Topic: Using the HOSTS file  (Read 8219 times)
FallowEarth
Inactive Moderator
TMN Veteran
*
Offline Offline

Gender: Male
Posts: 2871



View Profile
« on: May 08, 2006, 07:29:23 PM »

Disclaimer: testmy.net and its mods are not responsible for any damage to hardware, software, systems, or bodily harm if you decided to attempt this.


USING THE HOSTS FILE


A HOSTS file is used to map an Internet Protocol Address to a device on an IP routable network.  When a computer attempts to access a device by name (ie. URL), it will first check the HOSTS file to see if there is an entry for that name (provided that the DNS caching service is enabled on the machine).  If the name exists within the HOSTS file, the computer will then contact the associated IP address, bypassing the Domain Name System.  If the name does not exist within the HOSTS file, the computer will contact the DNS server to map the name to an IP address.

HOSTS files can be useful for a multitude of different things, from blocking ads, to blocking embedded objects, to redirecting URLs.  The purpose of this guide is to explain how to modify the HOSTS file to provide a solution for optimizing and modifying how webpages are displayed on your PC.


HOSTS FILE LOCATION


The file is titled "HOSTS" and is located:

Windows NT/2000/XP: %SystemRoot%\system32\drivers\etc\
Windows 95/98/Me: %windir%\
Mac OS X: /etc (uses BSD-style hosts file)
Linux and other Unix-like operating systems: /etc
OS/2 and eComStation: "bootdrive":\mptn\etc\



EDITING THE HOSTS FILE


Here are the standard contents of the HOSTS file:

Code:
# 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
   

You can edit the HOSTS file with notepad in Windows.  There are a couple of ways to do this:

A)  Browse to the directory which contains the HOSTS file.  Right-click the HOSTS file and select "Open" or "Open With..."  When a list of programs appears, select Notepad and click OK.

B)  Using the Run command (start >> run), you can specify for notepad to open the HOSTS file.  For example, on Windows 2000/XP, type into run:

Code:
notepad %systemroot%\system32\drivers\etc\HOSTS

Once you have edited the HOSTS file, you will be able to save it using notepad (File >> save)



NOTE:  You may want to back up your HOSTS file before editing it.  To do this, open the file in notepad.  Under File, select Save As.  In the Save as type: select All Files.  Save the file as HOSTS.bak in the same directory.


THE DNS CLIENT SERVICE


When using the HOSTS file in Windows 2000/XP, it is important that your DNS Client service is configured properly.  Checking this to see is easy.

-From Run, type services.msc
-Right-click DNS Client, select Properties
-Set Startup type to Automatic
-If Service status says stopped, you can click start to enable the service



AD FILTERING


STEP 1:  Obtaining the URL

A lot of ads either appear as popups, or are an integrated part of the coding of the site, thus the address does not appear in the address bar of the browser.  However, you can still obtain the URL.

Internet Explorer:  Right-click on the add, and select properties.  The address will the shown in the "Address (URL)" field.

Firefox:  Right-click, select View page info.  Under the General tab, the address will be shown in the URL field.


STEP 2:  Blocking the URL

The loopback (localhost) address is most commonly used to block unwanted content on the Internet.  The address is 127.0.0.1.  To block an address in the HOSTS file, you add an entry which contains the loopback address, and the URL for the site.  For example, an entry would be:

127.0.0.1 ad.doubleclick.net

The HOSTS file becomes:


Code:
# 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       ad.doubleclick.net

After you've made the entry, save the file and close notepad.

NOTE:  It may take up to 5 minutes for HOSTS file changes to take effect



HOSTS FILE TIPS


You can set a URL to any IP address (does not have to be 127.0.0.1).  This can be useful if you need to redirect a certain site when it is being accessed on your computer.  You just need to obtain the IP address to redirect to.  For example, you might redirect testmy.com to testmy.net:

67.18.179.85   testmy.com



You can increase the security of your HOSTS file by making it "Read-only."  This may prevent pests and malicious code from altering this file.  To do this:

-right-click the HOSTS file, select Properties
-In the Attributes part, click Read-only
-click Apply, click OK

Just be sure to remove the attribute before you attempt to make a change yourself, and put it back when you are finished.



Do not let your HOSTS file get to be too big, as it may eventually slow down your PC.  I have seen documentation which states that anything over 135 KB may be too large, but I have no trouble with a HOSTS file that size.  I would say that anything exceeding 256 KB may be getting a little large, and you may need to revise your entries.



RELATED UTILITIES


Some anti-spyware programs have HOSTS file protection.  Here are a few, with links:

Windows Defender
SpyBot Search & Destroy
SpywareBlaster
WinPatrol



RELATED LINKS


Blocking Unwanted Parasites with a Hosts File
Wikipedia - HOSTS file
What is the Hosts file?

« Last Edit: May 28, 2006, 07:05:01 PM by FallowEarth » Logged
Send this topic Print  Pages 1 Go Up
testmy.net Broadband  |  Main Forum  |  Guides  |  Topic: Using the HOSTS file « previous next »
Jump to:  

    
testmy.net's forum is proudly Powered by SMF | SMF © 2006-2007, Simple Machines LLC
Bookmark: Del.icio.us    StumbleUpon
 
 

 

© 1999-2008 testmy.net - Contact - Legal - Facts & FAQs
Page Loading Stats: This forum Page created in 0.116 seconds with 24 queries.