How to Edit Your Hosts File

There will be times when you will have to edit the hosts file on your computer or laptop. The reasons could be manifold including a third-part attack. Whatever the reasons, editing hosts file will give you the right to control web browsing and also manage traffic density to any particular websites. host files

What Are Hosts File?

Hosts files came into existence along with ARPANET. The files were used specifically before DNS to decide hosts names. Hosts files are large data based documents that help with the name resolution within the network.
Microsoft took the decision of storing line hosts file in Windows networking.

This is one reason the hosts file do not change whether they are used in Linux, Windows or OS X. The syntax for the hosts file remains more or less the same across all platforms of Windows. Some hosts files also give loopback various entries. We will use this as an example of how to edit hosts file.

Tips to Edit Hosts File

Firstly, decide upon an appropriate location where the address can be re-directed to. Secondly, decide on the address that requires to be redirected and thirdly, leave a suitable comment. The hosts file will read typically like: localhosts #loopback

Now that the host file is established, let us look at the ways in which it can be edited in different operating systems.

1. Ubuntu

Ubuntu 10.04 and Linux distro give you the freedom to edit the hosts file in the terminal itself. Simply select an editor tool or even the GUI text editor to begin editing the hosts file.

edit ubuntu host files

The hosts file for Ubuntu are available in the /etc/folder. This folder can be found in the root of the drive. We will use sudo to first open the file as root and then edit it.

edit ubuntu host files

Edit the file so that the Facebook site is redirected into nothing. Save the edited hosts file and try logging into Facebook. You will be redirected to a site that is actually not there!

facebook locked on ubuntu

2. Snow Leopard (OS X 10.6)

Snow leopard also gives you the freedom to edit the hosts file inside the terminal. You can use either your favorite editor or the GUI text editor for editing hosts file.

edit Snow Leopard host file

In case of Snow leopard, the hosts file is similar to the hosts file of Windows. However, it has some text unlike the one in Windows. Let’s redirect Facebook to a non-existent site.

redirecting facebook to a non-existing site

The loopback here is It will take you directly to the Apache test page.

unable to pen facebook

3. Windows 7

In order to edit hosts file in Windows 7, you will have to perform the below given steps.
Type c:\windows\system32\drivers\etc\hosts in the Run Line.

edit windows 7 host file

The command will open the notepad and the file. After the notepad is opened you can begin editing the file. For example, let us run a command to block a popular social networking site like Facebook. This is simple. Key in after # icon.

adding facebook to host file

With this you would have completed the editing for your hosts file. But remember, it is also important to save the edited Hosts file.

unable to open facebook

Try opening the Facebook homepage now. You will draw a blank. This means that you have successfully managed to block Facebook on your web browser.