Knowledgebase

The "hosts" file customization

The hosts file is used to establish correspondence between IP address and a domain locally. Information stated there has the highest priority and is spread only within the computer where this file is edited.

Contents

  1. Where the hosts file is located?
  2. How is the hosts file supposed to look like?
  3. How to edit the hosts file?
  4. How to save the hosts file?
  5. How to comment out the line in the hosts file?

1. Where the hosts file is located?

To find the hosts file in the system will be no trouble.

In case of Linux this file is located in the following directory: /etc/hosts
And in case of Windows: C:/Windows/System32/Drivers/etc/hosts

In Windows operating system destination path to the hosts file may be changed in the registry, which one can access with the editor regedit. One can run it the following ways:

1) Start Menu > Run > regedit > OK;

Hosts-file-1.jpg

2) Windows + R > regedit > OK.

The record we are interested in is located in:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\DataBasePath

Hosts-file-2.jpg

  • Open DataBasePath parameter and in Value field indicate a new path.

2. How is the hosts file supposed to look like?

By default in clear system there is no value in the hosts file but solely commended lines (started with # symbol) with the file description.
Some software can make its changes into the hosts file, e.g. to indicate which server updates should be downloaded from.

3. How to edit the hosts file?

  • Open hosts in any text editor available in the system. For Windows a standard “Notepad” or “Wordpad” will suit.
  • Go to the end of the file and add values in the following order:
         IP address     Domain name
  • After making changes save the file.
    Below you can see an example of indicating for the domain yourdomain.tld IP address 127.0.0.1

Hosts-file-3.jpg

One can check introduced changes for functionality by putting the stated domain into a browser or by pinging it in a command line.

Hosts-file-4.jpg

4. How to save the hosts file?

Sometimes there is a situation when the hosts file will not be saved and all introduced changes will not work. This situation emerges in several cases:

  1. Error “You don’t have permissions” is displayed. You need to make sure that you are opening the file with the rights of the superuser (administrator). As this is a system file, user without administrator rights cannot edit it.
  2. The file is saved in an incorrect format, e.g. hosts.txt. First of all you need to check whether there is a possibility in a text editor to save the file without extension. If not, you need to turn on the display of file extension in the system settings, to save the file in .txt format, and then to change its name, having deleted the previous hosts file beforehand.

5. How to comment out the line in the hosts file?

To commend out a line one uses the symbol “#”, puts it at the beginning oft the line and thus terminates operation of the record in the line. This method is convenient in case when some record may be needed in the future, or when there is a need to add some text with description. Also, a comment may be added not only at the beginning of the line, but for example, after IP address and  a domain name.

Hosts-file-5.jpg

Now working with hosts is over.

Do you need OpenVZ or XEN hosting? We offer European and American VPS with different types of virtualization and management options.

Also Read
PHP modes (Views: 873)

Language:

Quick Navigation

Client Login

Email

Password

Remember Me

Search