The hosts file is used to convert a symbolic domain name to an IP address
(for example, “unihost.com” in “18.104.22.168”) and vice versa. Simply put, the hosts file directs your computer to the server where the website is located, bypassing the DNS server, since this file is processed in the operating system before a request is sent to the DNS server.
The hosts file can be useful in cases:
- When the site is transferred to a new hosting, VPS / VDS or a dedicated server and you want to see how it is displayed, before changing the DNS records;
- When it became necessary to work with the site after changing the DNS records (until they were updated);
- When you do not have a registered domain, and you would like to check how the site functions on the hosting server without domain purchasing.
File location on different OS:
|UNIX и UNIX-подобные||/etc/hosts|
|Windows:95, 98, ME
NT, 2000, XP, 2003, Vista, 7, 8,10
|Mac OS 9 and earlier||System folder: Preferences or just in the system folder|
|Mac OS X и iOS||
The file syntax is very simple, even a beginner can figure it out. Listing a standard file:
|# 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
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
# For example:
# 22.214.171.124 rhino.acme.com # source server
# 126.96.36.199 x.acme.com # x client host127.0.0.1 localhost
Everything that is located after the “#” sign is a comment.
To edit the hosts file, you can use any text editor (for example, Notepad, Notepad ++, Kate, GEdit, VI and others). To open the necessary domain from the IP you need, for example, “188.8.131.52”, you need to make a record of the form:
“184.108.40.206” is the IP address of the server where the site is hosted, and “unihost.com” is the domain name from which the site should be opened.
That means so when you add a record of this kind, we directly tell the computer where to open the site from.
Important!!! Pay attention when viewing the site in this way it will be visible only to you or to those people who will make the same changes on their local PC. On the Internet, the site will be visible from the old hosting.
In order for the site to “look” at the new hosting, you need to change the DNS records.