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.


Share:

Leave a Reply