How to Update Hosts File Entry on Windows, Ubuntu and Mac

April 18, 2017 / How-to Guide
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. 

  1. Press Windows + R keys to Run Line.
  2. 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 
    location of hosts file
  3. 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.
    hosts file
  4. Now you have edited your Hosts file and save it.
    save file
  5. Now observe if we try to reach Facebook in IE browser we can’t get to the page.
    unable to page open
  6. We also were not able to access it in Google Chrome.
    google chrome

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.

  1. We will use VIM for this example.
  2. You will see that with Ubuntu there is similarly a section for IP6. For most needs, you will just need to edit it the top section and ignore the IP6.
    ubuntu hosts
  3. Now save the file and try to open Just like in windows we will see that we can’t get to the page.
    unable to connect

Edit Hosts file on Mac OS X (Any version)

  1. 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.
    hosts file mac
  2. The file will look like a Windows, simply with a little less explanation. Again we are going to redirect Facebook.
    add entry
  3. This time it looks like that is a loopback and will redirect you to the PCs Apache test page.


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.
Dominos Search