How To Modify Your Hosts Files On Windows, Mac And Ubuntu

On occasion, you will need to edit the host’s file on your machine. Sometimes because of an attack or prank, and others so that you can simply and freely control access to websites and network traffic.

Microsoft kept the host’s file alive in Windows networking which is why it varies very little whether used in Windows, OS X or Linux. The syntax stays mostly the same across all platforms. Most hosts files will have several entries for loopback. We can use that for the basic example of the typical syntax.

The first part will be the location to redirect the address to, the second part will be the address that you will want to redirect, and the third part is the comment. They can be separated by a space, but for ease of reading are typically separated by one or two tabs.

127.0.0.1 localhosts #loopback

Now let’s look at accessing the host’s files in the different operating systems…

Windows 8 or 8.1 or 10

Unfortunately, Windows 8 or 10 makes it annoying to open apps as administrator — but it’s not too difficult. Just search for Notepad, then right-click on Notepad in the search results list, and choose to run it as administrator.

Step 1 – If you’re using Windows 10 this will be on the Start Menu.

4cOMRyUtHWFyLdvkQX4KNPW6anv78Yer modify hosts files

If you’re using Windows 10, it’ll look more like this:

modify hosts files

Step 2 – Once you’ve done so, open up the following file using the File -> Open feature.

c:\windows\system32\drivers\etc\hosts

6NbU1PEgUR4HZtuwITyp5Micqoj3oFpQ modify hosts files

Step 3 – Then you can edit as normal.

Windows 7

Step 1 – To access the host’s file in Windows 7 you can use the following command in the Run Line to open notepad and the file.

notepad c:\windows\system32\drivers\etc\hosts

modify hosts files

Step 2 – Once notepad is open you can edit the file. In this example, we will block Facebook. To do this just enter the following after the # mark.

0.0.0.0 www.facebook.com

49kUhIyZUOXhHND7iHoWcqLlmEqGV3yE modify hosts files

Step 3 – Now that you have edited your Hosts file make sure to save it.

pMoQzPMdTzIlwMXwpWvLEyLS921yYMeb modify hosts files

Step 4 – Now notice if we try to access Facebook in IE we can’t get to the page.

JOTYyfPoJUiHnTziS3EG5OmpALkoXrFp modify hosts files

Step 5 – We also were not able to get to it in Google Chrome.

OV12rrc3LYrobtKTAIK4M0yvcGLYm6cB modify hosts files

Ubuntu

Step 1 – In Ubuntu 10.04 and most Linux distro’s you can edit the hosts file directly in the terminal. You can use your favorite editor or even open your favorite GUI text editor. For this example, we will use VIM. Like Windows 7, Ubuntu’s host’s file is located in the /etc/folder, though here it is in the root of the drive. In order to edit the file, you will need to open it as root which is why we use sudo here.

e2lZJVnUme987zVgPIP0IvYS8and5yGS modify hosts files

Step 2 – Now that it is open we can edit it to redirect Facebook into nothing. You will notice that with Ubuntu there is also a section for IP6. For most needs, you will only need to edit it in the top section and ignore the IP6.

modify hosts files

Step 3 – Now we can save the file and try to go to Facebook.com. Just like in windows we will see that we are now redirected to a site that does not exist.

modify hosts files

Mac OS X (Any version)

Step 1 – In OS X, accessing the host’s file is very similar to Ubuntu. Begin in the terminal and use your favorite editor, even is you wish to call a GUI text editor, it is easier to do so from the terminal.

YUX91InZEq16RyzalW6GtHMnqp3vFyAC modify hosts files

Step 2 – The file will look a bit more like Windows, only with a little less explanation. Again we are going to redirect Facebook.

62lRjFskOuVM2q1fq9uX7l22gRC4zusK modify hosts files

Step 3 – This time it seems that 0.0.0.0 is a loopback and will direct you to the computers Apache test page.

modify hosts files

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Scroll to Top

We can help you. Right now.

Fast growing merchants depend ServerGuy for high-performance hosting. Experience counts. Let's get started.

Talk to a sales representative

USA / Worldwide

+1.714.2425683

India

+91.9852704704