Vous êtes sur la page 1sur 6

Beginner Geek: How To Edit Your Hosts File

1 of 6

http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-yo...

Beginner Geek: How To Edit Your Hosts File


On occasion you will need to edit the hosts le 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 trac.
hosts les have been in use since ARPANET. They were used to resolve hosts names before DNS. hosts les would be
massive documents used to aide the network name resolution.
Microsoft kept the hosts le 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 les will have several entries for loopback. We can
use that for the basic example for the typical syntax.
The rst 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 lets look at accessing the hosts les in the dierent operating systems

Windows 8 or 8.1 or 10
Unfortunately Windows 8 or 10 makes it annoying to open apps as administrator but its not too dicult. Just search for
Notepad, then right-click on Notepad in the search results list, and choose to run it as administrator. If youre using
Windows 10 this will be on the Start Menu.

If youre using Windows 10, itll look more like this:

Once youve done so, open up the following le using the File -> Open feature.

4/12/2016 3:45 PM

Beginner Geek: How To Edit Your Hosts File

2 of 6

http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-yo...

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

Then you can edit as normal.

Windows 7
To access the hosts le in Windows 7 you can use the following command in the Run Line to open notepad and the le.

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

Once notepad is open you can edit the le. In this example we will block Facebook. To do this just enter in the following
after the # mark.

0.0.0.0

www.facebook.com

Now that you have edited your Hosts le make sure to save it.

4/12/2016 3:45 PM

Beginner Geek: How To Edit Your Hosts File

3 of 6

http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-yo...

Now notice if we try to access Facebook in IE we cant get to the page.

We also were not able to get to it in Google Chrome (check notes at the end). Also for more info on editing your Hosts le,
check out The Geeks article on how to create a shortcut to quickly edit your Hosts le.

Ubuntu
In Ubuntu 10.04 and most Linux distros you can edit the hosts le 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, Ubuntus hosts le is located
in the /etc/ folder, though here it is in the root of the drive. In order to edit the le you will need to open it as root which is
why we use sudo here.

4/12/2016 3:45 PM

Beginner Geek: How To Edit Your Hosts File

4 of 6

http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-yo...

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 the top section and ignore the IP6.

Now we can save the le 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.

Mac OS X (Any version)

4/12/2016 3:45 PM

Beginner Geek: How To Edit Your Hosts File

5 of 6

http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-yo...

In OS X, accessing the hosts le is very similar to Ubuntu. Begin in terminal and use your favorite editor, even is you wish to
call a GUI text editor, it is easier to do so from terminal.

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

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

Notes
There are some things to note from this walkthrough that we did notice. When tested it, Chrome did not use the hosts le
in any operating system but we were able to block Facebook in Chrome by adding www.facebook.com. Also, make sure to
place and extra line after the last entry for the section.
This should get you started in understanding the Hosts le and how it can help protect your computer. You can use it to
block sites that you dont want a PC to be able to access. If you have more suggestions for any of the operating systems we
coved, then leave a comment and let us know!
Create a Shortcut to Quickly Edit Your Hosts File in Windows

JOIN THE DISCUSSION

4/12/2016 3:45 PM

Beginner Geek: How To Edit Your Hosts File

6 of 6

Chris is a Mac geek who still knows his way around Linux and Windows. He's
always looking for a good way to translate geek to english.

http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-yo...

Published 02/1/15

SHOW ARCHIVED READER COMMENTS (19)

4/12/2016 3:45 PM

Vous aimerez peut-être aussi