2.19.7. Editing hosts file

The hosts file is used by the operating system to determine the address of specific resources instead of querying DNS. If the address of a specific resource is listed in the hosts file, a request will not be sent to the DNS server to retrieve the domain's information; when the domain is accessed, it will open directly from the address specified in the hosts file. Using this file is quite convenient for testing a site from another server without redirecting the domain directly to that server.

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

To check hosts file path, you can use registry editor. To do this, press Win+R, enter regedit and click "OK". You can find required parameter at this path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\DataBasePath.

Attention!

You may need administrator privileges to edit the hosts file in Windows.

To quickly open a file with administrator privileges, press Win+R, enter the path to the C:/Windows/System32/Drivers/etc/hosts file, and then press Ctrl+Shift and click "OK".

The file is usually located at /etc/hosts. On some operating systems, the path may differ.

The path may vary depending on the OS version.

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

On Android, the file is located at /system/etc/hosts.

In iOS, the file is located at /private/etc/hosts.

Entries in the hosts file are formatted as IP domain, separated by a tab (simply press Tab to insert a tab), and anything following the # symbol is treated as a comment:

In this example, there are three entries:

  1. localhost is pointed to IPv4 127.0.0.1 (accessing localhost is the same as accessing the local machine itself).
  2. localhost is pointed to IPv6 ::1 (equivalent to 0:0:0:0:0:0:0:1).
  3. Example of pointing example.com to the IPv4 XXX.XXX.XXX.XXX.
Content