Skip to content

Hosts file configuration

The hosts file is a plain text file used to map hostnames to IP addresses.^[600-developer__tools__vscode__vmware.md] This configuration allows systems to resolve network names locally without relying on a DNS server, which is particularly useful in virtualized environments or local testing scenarios.

File Locations

The location of the hosts file varies by operating system.

  • Windows: The file is located at C:\Windows\System32\drivers\etc.^[600-developer__tools__vscode__vmware.md]
  • Linux: The file is located at /etc/hosts.^[600-developer__tools__vscode__vmware.md]

Usage and Syntax

The configuration consists of lines that map a specific IP address to one or more hostnames.^[600-developer__tools__vscode__vmware.md] The general format is:

IP_ADDRESS hostname1 hostname2

For example, to map the IP 192.168.79.10 to the hostname w10, an entry would look like this: 192.168.79.10 w10

Linux Configuration Example

On Linux systems (such as CentOS or RHEL), the /etc/hosts file typically includes default entries for the loopback interface alongside user-defined mappings.^[600-developer__tools__vscode__vmware.md]

A typical configuration might look like this:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.79.10 w10
192.168.79.20 w20
192.168.79.21 w21

Once configured, the system can use the hostname for network operations.^[600-developer__tools__vscode__vmware.md] For instance, executing ping w10 will resolve to the mapped IP address (192.168.79.10), as seen in the output:

[root@w20 ~]# ping w10
PING w10 (192.168.79.10) 56(84) bytes of data.
64 bytes from w10 (192.168.79.10): icmp_seq=1 ttl=128 time=0.311 ms

Windows Configuration Example

Similarly, on Windows systems, the hosts file is edited to assign local names to static IPs.^[600-developer__tools__vscode__vmware.md] A common block of entries for a local cluster might look like this:

192.168.79.10 w10
192.168.79.20 w20
192.168.79.21 w21
192.168.79.22 w22
192.168.79.23 w23
192.168.79.24 w24
192.168.79.25 w25
192.168.79.26 w26
192.168.79.27 w27
192.168.79.28 w28
192.168.79.29 w29

  • [[Static IP]]
  • [[VMware]]

Sources

^[600-developer__tools__vscode__vmware.md]