Search Knowledge Base by Keyword

How to Modify your Hosts Files

Users can modify host files by overriding the domain name system(DNS) for a domain. By modifying host files, your hosting provider may offer you a temporary URL in the http://IP/~username format (where IP represents the server’s IP address and username represents the cPanel account name) to access your website.

This is useful, for example, if you migrate your website to a new server and want to test the site before you point the DNS records to it.

Modifying host files makes the change in your local machine to find out the Internet Protocol(IP) address that the user has specified.

However, some sites will not work with a temporary URL. For those sites, you can configure your workstation with the server’s IP address. To do this, modify your workstation’s /etc/hosts file to use the server’s domain name and IP address. 

This article explains how to modify your workstation’s /etc/hosts file.

On cPanel server, “mod_userdir” allows the user to access website through the temporary URL. “mod_usedir” can be accessed through this path – WHM >> Home >> Security Center >> Apache mod_userdir Tweak

Modifying the /etc/hosts file

The following methods allow you to modify your workstation’s /etc/hosts file.

Important:

Your workstation’s operating system will not remove your changes to the /etc/hosts file. If you want the domain that you added to use public DNS entries, you must manually remove the domain name and IP address in the /etc/hosts file.

MacOS® and Linux®

To modify your /etc/hosts file if your workstation runs MacOS or a Linux distribution, perform the following steps:

  1. On your workstation, open the /etc/hosts file with your preferred text editor.
  2. Add the server’s IP address and domain name under the last entry in the file, for example:1234127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.0.20    example.com1.2.3.4 username.example.comNote:In this example, 1.2.3.4 represents the server’s IP address, and username.example.com represents the domain name.
  3. Save your changes.
  4. Reload your browser for the changes to take effect.

Microsoft Windows®

To modify the /etc/hosts file on a Windows workstation, perform the following steps:

  1. Open the Start menu.
    1. If you run Windows 8 or Windows 10, type Win+X on the keyboard or click the Windows icon in the lower-left corner of your desktop interface.
    2. If you run Windows 7 or Windows Vista®, click Start.
  2. Enter Notepad in the search text box.
  3. Right-click Notepad and select Run as Administrator.
  4. In Notepad, open the following file:C:\Windows\System32\Drivers\etc\hosts 
  5. Add the destination server’s IP address and domain name under the latest entry in the file, for example:1234127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.0.20 example.com1.2.3.4 username.example.comNote:In this example, 1.2.3.4 represents the destination server’s IP address, and username.example.com represents the domain name.
  6. Save your changes.
  7. Reload your browser for the changes to take effect.
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.