How To Edit A Hosts File

In some instances you may find that you’re asked to or need to edit your hosts file. At this point you may be wondering what is a hosts file? A hosts file is a plain text file that is used to link host names to IP addresses. This article will cover how to locate and edit your hosts file on the Windows (7, 10), Linux and Mac OSX.

 

Windows 7

To modify your hosts file in Windows 7 you’ll need to open the hosts file up in Notepad with administrative permissions. This can be done by clicking the Start icon and searching for notepad.

 

 

Once the results populate, right-click notepad and select Run as Administrator.

 

Showing how to run Notepad as an administrator

 

Once notepad is open click on File, select Open then enter in the following file path and click Open:

 

 

 

With the file open you can make the necessary edits. When making these edits you’ll need to ensure that you follow the format of IP address then domain name. For example, we will edit tutorials.hostwinds.com so that it loads from 192.168.1.1 like so:

 

 

 

Once you have completed making your edits be sure to save the file.

 

Windows 10

To modify your hosts file in Windows 10 you’ll need to open the hosts file up in Notepad with administrative permissions similarly to editing this file in Windows 7. This can be done by clicking the Search bar and searching for notepad.

 

 

Right click notepad from the results and select Run as Administrator.

 

 

 

With notepad now open, click on the File option, select Open using the following path and finally Click the Open button.

 

 

 

Just like in Windows 7, with the file open you can make the necessary edits. When making these edits you’ll need to ensure that you follow the format of IP address then domain name. For example, we will edit tutorials.hostwinds.com so that it loads from 192.168.1.1 like so:

 

 

 

Once you have completed making your edits be sure to save the file by clicking File then selecting Save.

 

Linux/Mac OSX

In most Linux distros you can edit the hosts file directly from SSH or the terminal using your favorite text editor. Likewise, in OSX you can do the same thing. For this article we will be using CentOS 7 and the Nano text editor for Linux and vim for OSX. To begin editing the hosts file issue the following command in Linux.

 

 

 

As a non root user in Linux you’d use:

 

 

 

In OSX you’d use the following:

 

 

 

The hosts file should now be open and you can begin making your necessary edits. When making these edits you’ll need to ensure that you follow the format of IP address then domain name. For example, we will edit tutorials.hostwinds.com so that it loads from 192.168.1.1 like so:

 

 

 

Save the file in Nano by pressing CTRL+O  then Enter and finally CTRL+X .

In Vim you’d press the Esc key followed by the colon (:) key and then type wq! in the terminal.

 

Are There Other Options?

Typically host files are created and edited to review what your current web management tool populates prior to changing your DNS to your new host.  Although host files can help with this, there are other available, possibly easier options, to achieve the same goal.

Use Your Current cPanel In The URL

You can use the following, provided you have a cPanel account, by utilizing your dedicated IP and cPanel username as the following in the URL, replacing “xxx.xxx.xxx.104” with your IP and “cpanelusername: with your username provided:

 

xxx.xxx.xxx.104/~cpanelusername

 

Typing the following into your URL will show you whatever is within your CPanel >> File Manager >> public_html (root) folder.  Furthermore, if you need to examine deeper folders or files, you would just extend the “cpanelusername” with the directory you wish to review, like the following:

 

xxx.xxx.xxx.104/~cpanelusername/nextfolder/thisfile

 

Use Hosts.cx

One issue when examining your CPanel like above is certain plugins may or may not apply or function properly until fully utilized and hosted as intended.  Using https://hosts.cx/ is a great tool to fully examine what your web management tool will render when fully pointed to.  Simply put in your provided dedicated IP and website name within your web management tool and it will show you what would display if already fully hosted.

 

Hostcx screenshot

 

Helpful Related Articles

 


Share:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.