HOSTS file - Modify the HOSTS File in the Different OS?

What is a HOSTS file and How do you modify the HOSTS file in the different operating systems?

–>HOSTS File

The HOSTS file is found inside an operating system, that helps to resolve hostname with an IP address before checking in DNS.

In your system, you want to access www.yourdomain.com hostname your system first actually resolves the hostname with the IP address of the server.

To resolve the IP address it will first check inside the HOSTS file which is a simple text file that store entries of hostname with the IP address, and if not found then it goes to your Internet Service Provider(ISP) or DNS server

It is helpful in case of troubleshooting or publishing a website for testing purposes by giving entry in the HOSTS file which resolves hostname with IP address locally before checking in DNS.

To modify your HOSTS file in Linux

In Linux, the HOSTS file is found inside the /etc directory in the form of a simple text file that can be modified by using text editors like:

1) nano

2)vi

Open file using the nano editor:

# nano /etc/hosts

Open file using the vi editor:

# vi /etc/hosts

Image

Note: Use sudo before the following command if you don’t have root privileges:

After the file is open, give entries of IP address and hostname in the desired manner:

IP_address Hostname

For example:

111.222.111.222 www.yourdomain.com

And after that safe file with:

1) Press ctrl + o to save file and ctrl + x to exit from a file if you are using a nano editor.

2) Press Esc button and write :wq if you are using vi editor.

Image

To modify your HOSTS file in Windows 10

In windows operating system the hosts file is found inside the c:\\windows\System32\drivers\etc folder to configure it follow the steps:

1) Press Win + r button and search for notepad and should be open with run as administrator

the other entry will not get saved .

image

2) Click on File and select the open option, after that goes inside the above-specified folder.

image

3) Select All files and now select the hosts file.

image

image

4) After file is open give entry in the last block i.e. localhost name resolution:

# IP_Address Hostname

For example:

# 111.222.111.222 www.yourdomain.com

image

5) Now save the file with the ctrl + s button.

image

To modify your HOSTS file in Mac os

In Mac os HOSTS file is found under the following path i.e

/private/etc/hosts, you can easily edit it with nano editor by follows the steps:

  1. On your system, select Application > Utilities > Terminal to open a terminal window.

Image

  1. Now open the HOSTS file by using the following command:

# sudo vi /private/etc/hosts

Note: use sudo if you don’t have root privileges.

Image

  1. Now edit the hosts file.

Add your new mapping after the default mapping i.e. (12.0.0.1 – localhost).

  1. To save and exits the HOSTS file, press :wq.

Image

  1. Now ping with the same domain name to check the connection is established or not.

Image

CONCLUSION- The above configuration shows how you can troubleshoot and publish websites for testing purposes by modifying the HOSTS file.

Learn how to scale, manage, and optimize your applications with a SLB. Read our solution brief "Get More from Your Enterprise Network".

DOWNLOAD SOLUTION BRIEF

Get started with CloudMinister Today