The hosts file is used to map domain names (hostnames) to IP addresses. It is a plain-text file used by all operating systems including, Linux, Windows, and macOS.

The hosts file has priority over DNS. When you type in the domain name of a web site you want to visit, the domain name must be translated into its corresponding IP Address. The operating system first checks its hosts file for the corresponding domain, and if there is no entry for the domain, it will query the configured DNS servers to resolve the specified domain name. This affects only the computer on which the change is made, rather than how the domain is resolved worldwide.

Using the hosts file to map a domain to an IP address is particularly useful when you want to test your website without changing the domain DNS settings. For example, you are migrating your website to a new server, and you want to verify whether it is fully functional before pointing the domain to the new server. The hosts file can also be used to block websites on your computer.

In this article, we’ll provide instructions about how to modify the hosts file on Linux, macOS, and Windows.

Hosts File Format

Entries in the hosts file have the following format:

IPAddress DomainName [DomainAliases]

Copy

The IP address and the domain names should be separated by at least one space or tab. The lines starting with # are comments and are ignored.

#linux #windows #macos

How to Edit Your Hosts File on Linux, Windows, and macOS
1.65 GEEK