Blog Post

Apps on Azure Blog
2 MIN READ

Hostfile entry on Windows and Linux machine

ShrutiDave's avatar
ShrutiDave
Icon for Microsoft rankMicrosoft
Apr 11, 2024

The hosts file, commonly known as etc\hosts, functions as a text-based tool employed by operating systems like Windows and Linux, to establish associations between IP addresses and host names or domain names. Serving as a localized DNS service, it supersedes mappings provided by external DNS servers, enhancing efficiency in local domain resolution. Its location varies according to the operating system utilized. Failure to retrieve IP addresses from a locally installed server or resolve them through DNS can result in application startup issues, underscoring the critical role of the hosts file in network connectivity.

Steps to create hostfile entry on Windows Virtual Machine:

1. Open your text editor in Administrator mode. To do this, right-click on your text editor application (such as Notepad) and select "Run as administrator."

2. In the text editor, navigate to the directory C:\Windows\System32\drivers\etc. You may need to manually type this path into the file explorer address bar or use the "Open" dialog box within the text editor to navigate to this location.

3. Once inside the etc directory, locate the file named "hosts" and open it in the text editor.

4. Add the IP address and hostname entry in the following format: <IP_Address> <Hostname>

5. After adding the desired entries, save the changes to the hosts file. Make sure to save it without changing the file extension.

6. Close the text editor.

 

Steps to create hostfile entry on Linux Virtual Machine:

1. Open the terminal on your Linux system.

2. Use the nano command line text editor (or any other text editor available on your system) to open the hosts file. Enter the command: sudo nano /etc/hosts.


You may need to enter your Linux user password to proceed.


3. Add a new line at the end of the file with the IP address and the hostname you want to map to that IP address. For example, if you want to map the IP address 10.0.0.4 to the hostname contoso.com, you would add the line: 10.0.0.4 contoso.com.

 

 

4. Save the changes by pressing Ctrl+O, then press Enter to confirm the filename, and finally press Ctrl+X to exit the nano text editor.

 

5. To verify that the mapping is working, you can use the ping command followed by the hostname you just added to the /etc/hosts file. For example, to ping contoso.com, you would type ping example.com and press Enter.

 

Updated Apr 11, 2024
Version 1.0

1 Comment

  • Loic951's avatar
    Loic951
    Copper Contributor

    Hello ShrutiDave,

    My name is Loic, and I would like to raise an issue related to the Linux and Windows " etc hosts" file format. While working in client support, I frequently encountered a significant problem affecting many customers: their "hosts" files were often incorrectly formatted.

    This caused cloud servers to fail to communicate with one another, resulting in serious performance issues. Although each operating system has its own format and some flexibility is permitted, the examples provided by distributions such as Red Hat and Debian differ in their ordering for example: IP hostname FQDN, IP FQDN hostname ( But also Duplicate IP management) The problem is that some systems are unable to read the "etc hosts" file correctly when the structure is inconsistent.

    A second issue is that the "etc hosts" file was originally designed for small networks, and with modern DNS systems it is largely unnecessary. Poor maintenance or incorrect entries can create significant disruption in system communication.

    I believe the " etc hosts" file should be redefined in terms of both value and format. We are now at a moment in history where cloud platforms, AI systems, and large-scale distributed computing require very high levels of reliability, especially given the environmental and energy challenges we face.

    I have already contacted some open-source community groups and standards organisations such as IEEE and IETF. My question is: Do you know how I can contact Microsoft to discuss this further? who would be a good contact providing contact to integrate our discution group with Standardisation company related to this ?