18 December 2016

How to Block Websites on Android by Editing Hosts File

7 comments
There are a lot of unsafe and malicious websites out there. Due to online spam, illegal content, social media addiction and other bad things happening over Internet, it become necessary to block some sites on your children's phone. After all, it is solely your responsibility to keep them away from such things.

Block websites in Android

As like in Windows, there is a hosts file in Android system which allows you to re-direct domain names to an IP address of your choice. If you would like to block certain websites on your phone, you can simply add them in this hosts file. This is one of the best, effective and evergreen method. Here's a complete guide on this topic.

What is a hosts file in Android?


A hosts file is a simple plain-text file which is used for mapping hostnames to IP addresses. When you try to visit a website, browser will first search the hosts file to find the mapped IP address of that hostname.

If it's found there, then the web page will be accessed from that IP address, otherwise a query is sent to the DNS server (Domain Name System) to find the real IP address of hostname.

So basically, hosts file is used to re-direct domain name to an IP address of your choice. With this approach, we can block any website by re-directing it back to the system or Localhost. (I will explain it later)


Benefits of blocking sites through hosts file

  • Best thing is, it will block website across all browsers and apps in your Android phone. (One arrow, multiple targets)
  • You can also block ad servers and trackers to improve user experience and website loading time.
  • You can play a prank on your friends by blocking or redirecting some popular websites on their phone like Google and Facebook.

Block websites in Android with hosts file


This method will work only in rooted Android phones. First you need to install ES File Explorer app. As hosts file is located in the root directory of Android system, so it can't be accessed from normal file managers. Once after installing it, follow this step-by-step guide -
  1. Launch the ES File Explorer app and go to /system/etc/ folder.

    Open system hosts file

  2. Here find the hosts file and open it as Text.

    Open hosts file as text

  3. Then select the ES Note Editor app.

    Select ES Note Editor

  4. Now click the menu button (three dots at the top-right corner) and then tap Edit option.

    Edit hosts file and block websites

  5. To block a website, simply add this line: 127.0.0.1 example.com

    For example, if you want block Google, add this: 127.0.0.1 google.com

    Here 127.0.0.1 (or localhost) is the standard hostname given to the address of your device. When you write 127.0.0.1 google.com, it means google.com will be redirected to 127.0.0.1 IP address which is your localhost by default, hence website can't be accessed.
  6. Finally save the changes.
So this is how you can block certain websites in your Android phone by editing hosts file. If you are facing any problem, please do share in the comment section.

7 comments:

  1. It doesn't work

    ReplyDelete
  2. Replies
    1. The phone needs to be rooted first. It won't work otherwise.

      Delete
  3. You can't edit the hosts file on Android.

    ReplyDelete
  4. You forgot to mention that this method only works if the mobile is rooted.

    ReplyDelete
  5. Rooted but still failed, because the file system is read-only

    ReplyDelete
  6. Had the same problem as Jim, file can't be saved because it's read-only.

    ReplyDelete