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.
Hosts file location
Windows
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".
Linux
The file is usually located at /etc/hosts. On some operating systems, the path may differ.
macOS
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).
Android
On Android, the file is located at /system/etc/hosts.
iOS
In iOS, the file is located at /private/etc/hosts.
Editing hosts file
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:
localhostis pointed to IPv4127.0.0.1(accessing localhost is the same as accessing the local machine itself).localhostis pointed to IPv6::1(equivalent to0:0:0:0:0:0:0:1).- Example of pointing
example.comto the IPv4XXX.XXX.XXX.XXX.