What is a Hosts File?
You can set IP addresses for a domain on your local system through 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.
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.
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.
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/ folder, 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.
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.
If you find any difficulty with this, please feel free to get in touch with us via. Live chat or email.