Long before DNS, people have been using hosts files to resolve the names of hosts. They are huge documents which help out the network when it needs to resolve a name. Microsoft still uses them, and they can be found in Windows networking. However, you can find them in other popular operating systems as well, such as Linux or Mac.
There are times you’ll want to edit these hosts files. Maybe you want to control who can access what website on the network, and need to edit that in a hosts file. Or maybe you just want to play an innocent prank and freak someone out. Either way, there are steps you can take to access and edit hosts files.
As stated, these hosts are on several different operating systems, even though they originated from Windows. This means that you will be using the same syntax everywhere. The majority of said hosts files usually have multiple loopback settings. This is where you should start.
When looking at this syntax, you will see that it has three parts, which are usually separated by a space or a tab. The first of these is a string of numbers, or rather a redirection location. The next part is the address which you will redirect. Finally, you have the comment. An example of this is below.
127.0.0.1 localhosts #loopback
The question you undoubtedly have is “How do I access a hosts file in my own operating system?” This text will cover Windows, Linux, and Mac OSs and how to access their hosts files.
Windows 8, 8.1 and 10
Let’s first focus on Windows 8, 8.1 and 10, as it is more complicated to find the hosts files here. The biggest complaint a user has is that he or she cannot open apps and programs as an administrator. However, it’s easier than you think.
What you first must do is find Notepad and right-click on it within the search results. The option “Run as Administrator” is what you need. If you happen to have Windows 10, you’re in luck, as this will be right there on the Start menu.
Next, you must find the file with this location:
You must open it by clicking File, and then Open Feature. The minute you do so, you will be able to edit it without any problems.
Now let’s move on to Windows 7. For this step, you will need to use the Run command. Once you enter Run, click the following and open the file once it pops up:
With Notepad open, you will be able to edit this file. As an example of hosts editing, we will block a popular website, namely Twitter. Once the command pops in, write the following string right after the # symbol:
You’ve edited the hosts file. In order to keep it as it is, you will have to save it. Once you do this, you’ll want to click on the Internet Explorer, as this won’t work on Chrome and other browsers. When you type in the URL of the website we just blocked, it will appear as if it doesn’t exist. That means you’ve successfully edited the hosts file.
There are, of course, more ways to edit the hosts file in Windows, but the ones noted above are the only ones you’ll really need.
Popular among the tech community, Linux definitely benefits from you knowing how to edit hosts files. For this text, we will focus on Ubuntu 10.04, but the following procedure works on most Linux distros.
With Ubuntu, you can literally edit hosts files right there in the terminal. GUI text editors such as VIM will do fine for the editing. To locate the hosts files you need, find the folder called /etc/ and open it. The files should be right in the drive’s root. Because of this, you must open the hosts file as a root. Using sudo would work fine. You can enter by typing vim /etc/hosts, and there you are.
Let’s use Google.com as an example. The same string with four zeros applies as it did with Windows. However, when you do this edit, a section for editing IP6 will pop up. Don’t worry about that, as most of the time you will have no need to edit anything else other than the lines above the IP6. So ignore it and go about your editing business.
Once you’ve done everything above, save the document and exit the whole thing. Next, go to your browser and try finding Google’s main page. It will, of course, redirect you to a page where there’s nothing as if there is no Google at all. Much like in Windows, you’ve successfully edited the hosts file to redirect any potential Google fan to an empty page.
Mac is, in a few ways, similar to both Windows and Linux when it comes to editing hosts files. For example, both Ubuntu and Mac have a similar way of accessing hosts. With Mac, you need to use the terminal via an editor of your choice. Doing everything from a terminal is far easier, and that includes calling a GUI text editor.
When you open the file, it will look like the one you got in Windows. However, this one explains far less than its Microsoft counterpart. We will be blocking Twitter again using the same string.
It is here that you’ll notice a difference. Using 0.0.0.0 will actually cause a loopback. Every time you click on Twitter within your browser, it will redirect you to the Apache test page of your computer.
As stated above, Chrome will be a bit of an issue. This browser does not use hosts files anywhere, whatever OS you might be using. But it’s still possible to block pages in it. You simply add the address of the page you want blocked. Don’t forget to put an additional line right after the final entry for this section, otherwise it won’t work.
Why go through all of that? Well, sometimes you don’t want your computer to have access to certain pages. As such, blocking them makes sense, and doing so is similar in all three major operating systems. Some additional steps are needed for third-party browsers, but all built-in browsers accept these changes without a problem. Naturally, you can also unblock pages later if you need to, and instructions to do so can be found online as well. Until then, enjoy blocking unnecessary content on your PC and keeping it clean.