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.
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
– This is the location of hosts file in Windows

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

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

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

STEP 6: We also were not able to access it in 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.
STEP 1: We will use VIM for this example.

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.

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.

Edit Hosts file on 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.

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

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.
