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

October 9, 2020 / How-to Guide

What is a Hosts File?

You can set IP addresses for a domain on your local system by editing hosts file that can overrule the authoritative DNS. It can allow you to check, what a domain will show if it’s pointed to a different server.

The hosts file will be edited to block certain hostnames (like advertising/malicious hosts), or used for web development purposes, i.e. to redirect domains to local addresses.

Windows

To access the host file in Windows XP, Vista, 7, 8x, and 10 you have to use the following command in the Run Line to open the file with Notepad.

  1. Press the Windows + R keys to Run Line.
  2. Copy the below-mentioned command and paste it into the Run Line.
        notepad c:\windows\system32\drivers\etc\hosts

    command prompt
  3. When the screen is open you can edit the host 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

    notepad
  4. Now that you have edited your Hosts file, save it.
    save
  5. Now observe if we try to reach Facebook in the IE browser we can’t get to the page.
    browser
  6. We also were not able to access it in Google Chrome.
    google chrome

Ubuntu

You can change the hosts file directly through the terminal on Ubuntu 10.04 and most Linux distros. You can use your favorite editor or even open your favorite GUI text editor. Like Windows 7x, Ubuntu’s hosts file is placed in the /etc/ folder, however here it is the root of the drive. 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.
    ubuntu
  2. You will see that with Ubuntu there is similarly a section for IP6. For most needs, you will just need to edit the top section and ignore the IP6.
    IP
  3. Now save the file and try to open Facebook.com. Just like in Windows we will see that we can’t get to the page.

    browser

 

Mac OS X (Any version)

 

  1. In Mac OS X, editing the hosts file is similar to Ubuntu. Begin in the terminal and use your preferred editor or even open your favorite GUI text editor, it is easier to do so from the terminal.
    mac os
  2. The file will look like a Windows, simply with a little less explanation. Again we are going to redirect Facebook.
    terminal
  3. This time it looks like 0.0.0.0 is a loopback and will redirect you to the PCs Apache test page.
    working

If you find any difficulty with this, please feel free to get in touch with us via. Live chat or email.

Spread the love