2.20.7. Edit hosts

The hosts file is used by the operating system to determine the address of certain resources instead of querying DNS. If the address of a certain resource is specified in the hosts file, the request will not be sent to the DNS server to obtain domain data; when the domain is opened, it will be opened from the address specified in the hosts file. The use of this file is quite convenient for testing the operation of the site from another server without directing the domain directly to this server.

Usually the file is located along the path C:/Windows/System32/Drivers/etc/hosts or %SystemRoot%\system32\drivers\etc\hosts, but it can be changed in the registry.

You can use the Registry Editor to check the path to the hosts file. To do this, you need to click on Win+R, enter regedit and press «OK»... The required parameter can be found along this path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\DataBasePath.


Administrator rights may be required to edit the hosts file on Windows.

To quickly open a file with administrator rights, you need to click Win+R, specify the path to the file C:/Windows/System32/Drivers/etc/hosts and holding the buttons Ctrl+Shift, click on the «OK».

Usually the file is located along the path /etc/hosts... On some operating systems, the path may differ.

The path may be different depending on the OS version.

On macOS 9 and earlier, the file is located in the system directory or a subdirectory of it preference... On macOS 10 and later, the file is located in /private/etc/hosts or /etc/hosts (/etc on OS X, a symbolic link to /private/etc).

In Android, the file is located along the path /system/etc/hosts.

On iOS, the file is located along the path /private/etc/hosts.

The hosts file contains entries in the form IP domainbetween which a tab should be set (to indent, just press Tab), everything after the symbol #, is considered a comment:

In this example, there are three entries:

  1. Direction localhost on IPv4 (a call to localhost is a call to oneself).
  2. Direction localhost on IPv6 ::1 (equivalentto 0:0:0:0:0:0:0:1).
  3. Example direction example.com on IPv4 XXX.XXX.XXX.XXX.