101 Basics: The HOSTS File and Routing

Well hello.  A little while ago I was surprised when a number of people stared blankly at me when I suggested that they alter their HOSTS file.  I’ve been meaning to write up a short entry on what it is and where you find it. 
 
I know this will seem pretty straightforward to many people, but for those who don’t know what it is or what it does.. you should read on.  Keep reading also if you don’t know how to manipulate the ARP or Routing Tables.
 
Well, let me begin by saying that the HOSTS file has been around for a long, long time.  You’ll even find the same file on a *nix system.  It goes way back to the old operating system kernel days. 
 
Basically, the file contains a list of IP address and DNS name pairs.  The file has no extension, so you’ll need to open it in Notepad.exe or a similar text editor manually.  It’s located in the %SystemDrive%\Windows\System32\drivers\etc folder.
 
Each line in the file should be formatted either with the first character being a hash/pound (#) which indicates a comment line (the line is ignored when the OS parses the HOSTS file).  Any line NOT beginning with a hash/pound (#) is interpreted as an IP Address – to – DNS resolution directive.  The format is {IP Address}{Tab}{DNS Name}.  The following is an example from a typical HOSTS file:
 
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
 
For IPv6 Addresses, you can use the proper addressing, e.g.:
# ::1             localhost
 
Note that any additions or subtractions from the HOSTS file might not take effect for applications or services running on the machine until they are restarted.
 
Why is this handy?  Well, for one thing sometimes it is nice to be able to force an address to resolve to a specific IP address.  This is specifically useful for testing software or network related products.  Especially, say, if you had a production environment and a test environment.  Any hard baked URLs would be problematic to go and manually redirect to a staging environment, so it saves time if you can simply set the redirect in a single file.
 
Yes, you can manually enter a change in the system’s route but this can be messy and tricky. 
 
ARP and ROUTE
 
If you want to learn more about networking and how it all happens, check out the following shell commands: ROUTE (Network Routing Tables) and ARP (Address Resolution Protocol – manipulate the ARP Table).  Also check out the tracert command.  It allows you to watch the hops between your computer and a destination DNS name or IP Address.
 
Of course, be wary in making changes to these two!  Only edit if you are confident you understand what you are doing.  Also, it’s worth taking the time to point out that if you use ipconfig /all you’ll be able to view the MAC addresses of the network adapters in your computer.  Handy info.
 
/R
 

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.