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.
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.
- Press the Windows + R keys to Run Line.
- Copy the below-mentioned command and paste it into the Run Line.
- 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.
- Now that you have edited your Hosts file, save it.
- Now observe if we try to reach Facebook in the IE browser we can’t get to the page.
- We also were not able to access it in Google Chrome.
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.
- We will use VIM for this example.
- 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.
- 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)
- 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.
- The file will look like a Windows, simply with a little less explanation. Again we are going to redirect Facebook.
- This time it looks like 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.