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.