How to Edit Your Hosts File on Windows, Mac, or Linux

A hosts file is a plain text file that maps your hostnames to Internet Protocol (IP) addresses. Whenever Windows connects over a network using a hostname, it refers to the hosts file.

Why do you want to Change your Hosts File?

Changing your hosts file is a temporary measure to preview your site as it will load from your Verpex server using the preview link ( https://sitepreview.org/).

You can make changes on a server other than the one loaded by your domain using a hosts file while visitors visit your webpage.

It allows you to test how your website looks on a different server when your DNS has not propagated.

You can also use the hosts file to control access to certain websites or network traffic.

Your host file might have been edited maliciously in an attack, this is known as a hosts file hijack. It is worth checking your hosts file for suspicious entries

How To Edit Your Hosts File on Windows

  • Find Your IP Address(you can retrieve this information easily using the cPanel dashboard)
  • Run Notepad as an Administrator
  • To get administrator access, press the Windows key and type Notepad into the search box.
  • Right-click on Notepad
  • Click Run as Administrator. You will get a prompt whether you want to allow this application to make changes to your device.
  • Select Yes(enter an administrative password when prompted).
  • Make Your Changes
  • Edit the hosts file. In the Notepad, select File > Open.
  • Navigate to C:\Windows\System32\drivers\etc . Alternatively, you can copy/paste this file path C:WindowsSystem32driversetchosts into the address bar
  • Press Enter.
  • Change the file filter from “Text Documents (.txt)” to “All Files (.*)”
  • Find the “hosts” file and click open.
  • Edit the hosts file.
    You will see some text describing the file’s purpose

This is a sample HOSTS file used by Microsoft TCP/IP for Windows.

This file contains the mappings of IP addresses to host names. Each

entry should be kept on an individual line. The IP address should

be placed in the first column followed by the corresponding host name.

The IP address and the host name should be separated by at least one

space.

Enter your custom IP address and hostname at the end of this file.
Remember to place each entry on a separate line If you are adding multiple entries,
Save changes and close the hosts file.

Edit The Hosts File On Ubuntu

You can edit the hosts file in the Terminal by using your favourite command-line editor
We will be using Vim which is one of the traditional text editors in Linux. Ubuntu’s hosts file is located in the /etc/ folder. To use, Vim, you will need to launch it prefaced by sudo, however, if Vim is not installed, just run “sudo apt install vim” in a Terminal.

  • Run "sudo vim \etc\hosts" in a Terminal.
  • Open up a Terminal, then enter:
    sudo vim /etc/hosts
  • Enter your password and edit
  • You will notice that with Ubuntu there is also a section for IPv6, ignore it, and edit the IPv4 section only.
  • Add an entry in the hosts file.
  • Save the file
    Note: If your browser has been configured to use DNS Over HTTPS and its own DNS Server, editing the hosts file will probably not block access.

Editing Hosts File on Mac

Running Vim as Sudo is the only way to access the hosts file. You'll be prompted for a password.

  • To locate the Mac hosts files location: Navigate to the Terminal application.
  • Type Terminal on the Spotlight or by going to Applications > Utilities > Terminal.
  • Enter this command
sudo nano /private/etc/hosts
  • Use the following command if the permission on the hosts file has been locked
sudo chflags nouchg /private/etc/hosts.
  • Type the password when prompted.
  • The hosts file contains some comments starting with the # symbol and some default hostname mappings (e.g., 127.0.0.1 localhost).
  • Enter your custom IP and hostname underneath the default ones.
    891.23.45.67 testing.com www.testing.com
  • Save the file and exit the editor once done

Editing Hosts File in Unix

You can find the hosts file at /etc/hosts on Unix-based systems, y. Most distributions of Unix will have terminals located in the same location.

  • Open the terminal
  • Go to Menu.
  • Choose Applications.
  • Select Accessories.
  • Click Terminal.
  • Type the command in the Terminal
sudo nano /etc/hosts
  • When prompted, type your user password
    The hosts file contains some comments lines starting with the # symbol and some default hostname (e.g., 127.0.0.1 localhost).
  • Enter your custom IP and hostname underneath the default ones.
    891.23.45.67 testing.com www.testing.com
  • Save the file and exit the editor once done

To make sure the changes are implemented swiftly, it is recommended to flush the DNS cache.

  • Click on the Windows button
  • Search for the command prompt and type the following command
ipconfig /flushdns
  • Press the Enter key.
    Windows should be using your new hosts file settings once this process is complete, you could just restart your computer to flush DNS