As you probably know, a hosts file is basically a plain text file that contains a list of host names and their associated IP addresses.
If you want to block access to certain websites (such as advertising/malicious hosts) or test the website before it goes live or redirect domains to local addresses, updating the hosts file will help you accomplish that.
In this knowledgebase, we will discuss how to update hosts file in Windows, Ubuntu and Mac OS.
Edit hosts file in Windows
To Update the hosts file in Windows XP, Vista, 7, 8x, 10 you have to use the following command in the Run Line to open the file with notepad.
- Press Windows + R keys to Run Line.
- Copy the below mentioned command and paste into the Run Line.
notepad C:\windows\system32\drivers\etc\hosts
This is the location of hosts file in Windows
- When notepad is open you can edit the hosts file.
For example, we will block Facebook. To block Facebook just enter following the line after the # mark in the hosts file.
0.0.0.0 www.facebook.com - Now you have edited your Hosts file and save it.
Edit Hosts file in Ubuntu
You can change in the hosts file directly through the terminal on In Ubuntu 10.04 and most Linux distros. You can use your favored editor or even open your favorite GUI text editor. Like Windows 7x, Ubuntu’s hosts file placed in the /etc/hosts, however here it is the root of the drive. In order to edit the file, you should open it as root which is why we use sudo here.
- We will use VIM for this example.
Edit Hosts file on Mac OS X (Any version)
- In Mac OS X, editing the hosts file is similar to Ubuntu. Begin in terminal and use your preferred editor or even open your favorite GUI text editor, it is easier to do so from terminal.
- The file will look like a Windows, simply with a little less explanation. Again we are going to redirect Facebook.
Conclusion
As we have seen above, the process of updating the hosts file on Windows, Ubuntu and Mac is the same. You need to open the file and add a new line with the IP address and domain name you want to map. Remember, incorrect changes to the hosts file can cause problems with your system’s network connectivity. So it is very important to make changes carefully.
Also Read : Disable the hosts file entries