How and why to modify my hosts file?

The hosts file is a computer file used by the operating system to connect host names (domain names) with IP addresses. In other words, it allows you to manually point a website address to a desired IP, or block access to a site altogether by pointing to an invalid or internal IP. This can come in handy when you have pointed the nameservers of your domain to a new web host and want to work on your website immediately.

Another thing you can use it for is to block access to malicious sites or specific sites to your employees or children for example. You can make the local computer resolve e.i. www.facebook.com through an invalid IP and that way prevent people from opening it. Since it is necessary to have administrative access to edit the hosts file, it will be really hard for someone to revert this change.

cPanel Hosting from WebhostFace

Modifying the hosts file under Windows OS

  • Open your system root folder, most commonly C:\Windows and navigate to System32\drivers\etc
  • Click on the hosts file with the right mouse button and select Edit with Notepad from the drop-down menu.
  • Go to the bottom of the file and add the desired IP followed by the host name (or domain name). Save the file and you are all set.

modify hosts file

Modifying the hosts file under MAC OS

  • Launch Terminal, type sudo nano /private/etc/hosts and press Return. You’ll need to also enter your admin password to execute it, as with all sudo commands.
  • You will now have the hosts file open in the Nano editor. Use the arrow keys on your keyboard, to navigate and edit the file.
  • Like with the Windows method above you should just add the desired IP followed by the host name (or domain name).
  • Press Control-O to save the file.
  • Use your Web browser to test the changes and flush the cache with dscacheutil -flushcache if they still haven’t taken into effect.

Modifying the hosts file under Linux

  • Launch Terminal, type sudo vim /etc/hosts and press Enter. Enter your administrator password (if needed).
  • You will now have the hosts file open.
  • Like with the Windows & MAC method above you should just add the desired IP followed by the host name (or domain name).
  • Press Control-O to save the file.
  • Use your Web browser to test the changes and flush the cache with dscacheutil -flushcache if they still haven’t taken into effect.