The hidden advantages of the hosts file.

Filed in windows operating system Leave a comment

The hidden advantages of the hosts file.

Can’t accessing a server by name but you can ping it by IP address?
More often than not you’re probably experiencing an issue with the DNS(Domain Name System.)

First check to see if your DNS entries are correct. In most windows environment you can access the DNS entries using the following method:

  • Click Start.
    start button
  • Select My Network Places.
    my network places
  • Select View network connections.
    view network connections

    Depending on the medium you are utilizing to connect to the internet you will either right click on Local Area Connection (wired) or Wireless Connection (wireless.)
    local area connection

  • Select Properties.
  • Scroll down until you see Internet Protocol (TCP/IP), highlight it and click on Properties.
    tcpip properties
  • At the bottom of the Internet Protocol Properties box you will now see the settings for DNS. Most home networks will utilize the DNS settings from their internet service provider and therefore the setting is configured as ‘Obtain DNS server address automatically.’
    dns settings

If you are in a highly secure network your administrator might choose to manage an internal DNS server. In this instance you will need to contact them for the IP address to input in this section.

OK so what happens if you can’t get a hold of the admin for the address or it just plain won’t work?

Finally, we get on to our topic!

Inside all version of windows and even Macs and Unix there lies a powerful but often overlooked file called hosts. In windows you will find it in the directory(%SystemRoot%\system32\drivers\etc\)
%SystemRoot% refers to the location of your windows folder. For most users this will be c:\windows or c:\winnt. Double-click on the hosts file. Since the hosts file has no extension you will need to designate an application to open the file. Select notepad from the list and then click open.
host file path

[*If you receive an error message saying you don't have admin rights you're pretty much screwed. You will require admin rights to open and edit the hosts file. All other non-screwed users please continue reading.]
You will see the following text in notepad by default if you have never edited the file before:
# 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

The description of the file explains the function and usage of the hosts file. In a nutshell the hosts file will allow you to assign hostnames to an IP address.

For example and also referring back to our original dilemma ::
(You’re trying to access a local server called “myserver” but you’re receiving an error that the path does not exist. Bummer. You visit another user’s machine on the same domain and network and they are able to access “myserver.” Being the tech savvy individual that you are you perform a ping command on “mysever” and obtain the IP address. You return back to your computer and perform a ping command to the IP address you just obtained and receive a response. You check your DNS settings and everything appear correct…so now what?) Answer: You edit the host file and assign “myserver” to the ip address you obtained. Let’s say the IP address was On the bottom of the hosts file you will add the line:     myserver

Save the file and then try accessing “myserver” again. If performed correctly, “myserver” will now point to which we already know is reachable. Problem Resolved.
Please keep in mind that although you are now able to access the server the hosts file is often used as a temporary solution. Network environments often change and if the IP address of the sever ever changes it will require an update on your part to update your own hosts entries. Troubleshooting and resolving your DNS issue will prove to be a more permanent solution.

, , , , , , , ,