On occasion, there might arise a need for you to edit the hosts file on your device. Sometimes the reason may be due to an attack or a prank, some other times it might be because you want to simply as well as freely control access to websites and network traffic.
What is the use of host file?
Host files is used to convert a request by name to a numeric IP address either on the local network or the Internet. HOSTS files are used to override the DNS system, that is for testing purposes so that a Web browser or any other application can be redirected to a specific IP address.
Hosts files are being used since ARPANET. These were used before DNS to resolve hosts names. Hosts files would be massive documents used to aid the network name resolution.
What does hosts file contain?
The hosts. Txt file is a plain-text file that accommodates a list of host names along with their corresponding IP addresses.
Microsoft had kept the hosts file alive in Windows networking which is the reason why it varies very little whether used in Windows, macOS, or Linux devices. The syntax is mostly the same across all of the mentioned platforms. The majority of the hosts files will have several entries for loopback. We can use that as the basic example for the quintessential syntax.
The first part contains the location to redirect the address. The second part contains the address that you will want to redirect. The third part is the comment. These can be separated using a space, however, for ease of reading, they are typically separated by either one or two tabs.
127.0.0.1 localhosts #loopback
Now let’s take a look at how you can access the hosts files in the different operating systems…
How to Edit Hosts files for Windows 8/8.1 as well as 10?
Unfortunately, if you are using Windows 8 or 10, they make it annoying to open apps as administrator. However, it is not too difficult. To begin the search for Notepad, then right-click on Notepad in the search results list, then click on the option that says to run it as administrator. If you are using Windows 10 this can be found in the Start Menu.
After you have done as stated above, open up the following file using the File -> Open feature.
Here you can edit host files as normal.
How to edit Hosts files for Windows 7?
If you want to access the hosts file in Windows 7 you have the ability to do so by using the following command in the Run Line to open notepad and the file.
After the notepad is open you can edit the file. In this article, we will be blocking Facebook as an example. To do this just enter the following after the # mark.
Now that you have edited the Hosts file remember to save it.
After we make the above change notice that if we try to access Facebook in IE we cannot get to the page.
We also were not able to get to Facebook even in Google Chrome. (For further information check notes at the end).
How to edit Hosts files for Ubuntu?
In Ubuntu 10.04 as well as most Linux distro’s you have the ability to edit the hosts file directly in the terminal. You can also use your favorite editor, or you could just whip open your favorite GUI text editor. For this article, we will be using VIM. Like in Windows 7, Ubuntu’s hosts file is located in the /etc/ folder. Though here it is at the root of the drive. In order to be able to edit this file, you will have to open it as root, that is the reason why we use sudo here.
After it is opened, we can then edit it to redirect Facebook into nothing. You will notice that while operating with Ubuntu there is also a section for IP6. For most requirements you will only have to edit in the top section, then ignore the IP6.
After we are done, we can save the file, then try to visit Facebook.com. Just like in windows we will be able to see that we are redirected to a site that does not exist.
How to edit Hosts files for macOS (Any Version)?
In macOS, the process of accessing the hosts file is similar to Ubuntu. You have to begin in the terminal, then use your favorite editor, if you wish to you can even call a GUI text editor, however, it is easier to do so using the terminal.
The file will look a bit more like Windows, the only difference being that this has a little less explanation. Again, we will be going to redirect Facebook.
This time it seems that 0.0.0.0 is a loopback, this will direct you to the computer’s Apache test page.
The Finishing Notes
There are a few things to note from this walkthrough that we did notice. When we tested after blocking Facebook, Chrome did not use the hosts file in any operating system, however, we were able to block Facebook in Chrome thanks to us adding www.facebook.com. Also, make sure you place an extra line after the last entry for the section.
This should get you started in understanding the Hosts file as well as how it has the ability to help protect your computer. You also have the ability to use it to block sites that you don’t want a PC to be able to access. If you are having any more suggestions for any of the operating systems covered in this article, then leave a comment down below.
If you liked this article (or if it helped at all), leave a comment below or share it with friends, so they can also know How to Edit Your Hosts File on Windows, Mac, or Linux.