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

What is a Hosts File?

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

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

Windows

To access 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.

STEP 1: Press Windows + R keys to Run Line.

STEP 2: Copy the below mentioned command and paste into the Run Line.

notepad c:\windows\system32\drivers\etc\hosts

win-1

STEP 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.

0.0.0.0    www.facebook.com

win-2

STEP 4: Now you have edited your Hosts file and save it.

win-3

STEP 5: Now observe if we try to reach Facebook in IE browser we can’t get to the page.

win-4

STEP 6: We also were not able to access it in Google Chrome.

win-5

Ubuntu

You can change within the hosts file directly through the terminal on In Ubuntu 10.04 and most Linux operating system distros. you’ll use your favored editor or maybe open your favorite GUI text editor. Like Windows 7x, Ubuntu’s hosts file placed within the /etc/ folder, but here it’s the root of the drive. so as to edit the file, you should open it as root that is why we use sudo here.

STEP 1: We will use VIM for this example.

ubuntu-1

STEP 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-2

STEP 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.

ubuntu-3

Mac OS X (Any version)

STEP 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.

Mac-1
STEP 2: The file will look like a Windows, simply with a little less explanation. Again we are going to redirect Facebook.
mac-2

STEP 3: This time it looks like that 0.0.0.0 is a loopback and will redirect you to the PCs Apache test page.

mac-3

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