How to edit hosts file in Linux & Windows Cloud Servers

2020-02-04 By Gary 10087 Views linux windows hosts networking
33 reviews

The hosts file is a file used to convert domain/hostnames to IP addresses. Adding an entry to hosts file helps you to override DNS for a domain/hostname and use the IP specified in the hosts file to resolve the domain/hostname on a specific machine.

Hosts file entry contains the IP address to which you want the domain/hostname to resolve.

123.123.123.123 layerexample.com www.layerexample.com


See the instructions for editing hosts file on Linux & Windows below.


Linux

The hosts file location for the Linux system is as follows :

# /etc/hosts
  1. Open a console and enter the following command to open the hosts file in VI editor.

    # vi /etc/hosts
    

    hosts1

  2. Add the entries as follows in this file and save.

    123.123.123.123  layerexample.com  www.layerexample.com
    
  3. After saving, you could see layerexample.com and www.layerexample.com resolve to 123.123.123.123.

    hosts2


Windows

The hosts file location for Windows system is as follows:

# /etc/hosts
  1. Select Start > All Programs > Accessories.

  2. Right-click Notepad and then select Run as administrator.

    hosts3

  3. Open the file C:\Windows\System32\drivers\etc\hosts in Notepad.

    hosts4

  4. Add the entries as follows in this file and save.

    123.123.123.123  layerexample.com  www.layerexample.com
    

    hosts5

  5. After saving, you could see layerexample.com and www.layerexample.com resolve to 123.123.123.123 from the command prompt.

    hosts6

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.