How to edit hosts file in Linux & Windows Cloud Servers

2020-02-04 By Gary 2797 Views linux windows hosts networking
58 reviews

The hosts file is a file used to convert domain/hostnames to IP address. Adding 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 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 command prompt.

    hosts6

What do you think about this article?

Rate this article