Hostfile entry on Windows and Linux machine
Published Apr 11 2024 03:45 AM 1,422 Views
Microsoft

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.

ShrutiDave_0-1712828484144.png
You may need to enter your Linux user password to proceed.

ShrutiDave_1-1712828484145.png


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.

 

ShrutiDave_2-1712828484147.png

 

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.

ShrutiDave_3-1712828484149.png

 

Co-Authors
Version history
Last update:
‎Apr 11 2024 02:55 AM
Updated by: