How To Modify Hosts File & Block Websites On Android [rooted device]

As we all know we can block any websites from our computer using windows host files. If we are using wireless router, then also we can blog website using router, so we can prevent our children accessing porn sites from their device. But this is limited to wifi connection only, what if they activate data plan on their mobile and start using such sites? Well, you can edit & modify android host file to block specific websites. You can monitor your child’s activity on android, to check which sites they browsing most often. If you think the sites they are browsing are unsafe for your children, you can block that site using your computer by using following tutorial.

Related : Block Ads on Android

Please note that the process requires rooted android device. So you must root your device before you start the procedure. If you don’t know how to root your android device, just comment your android device’s model number, name and specification if any. We will write tutorial on how to root your device here.

How to Modify Hosts File on Android:

This is the easiest way to edit hosts file on your android device, you can use Android Debug Bridge(ADB). So setup & install the Android Debug Bridge Utility.Once you have done, navigate into the folder where ADB is located and type cmd into the location bar, which will open a command prompt in the current folder.

 Edit hosts file on android device using Android Debug Bridge

Once command prompt window opens, type “adb devices” without quotes to see what device is attached to your computer.

Edit Android Hosts File

Now you will need to get location of Android Hosts file and download it, so that you can modify it and add the sites that you want to get blocked on your android smartphone.Type the following command on command prompt.

adb pull /system/etc/hosts F:\hosts

What the command do is, it will copy the android hosts file from system>etc>hosts and will copy it on your computer’s F drive.

Opening Hosts FIle from Local Drive

Right click on the hosts file copied in your F drive and open it with notepad. Once it opened, you will see the notepad file as shown in image with some entries. Here you will can add as many sites as you want. Suppose you want to block yahoo.com site, you will need to add 127.0.0.1 yahoo.com at the bottom. if you want to block thepiratebay , add another entry 127.0.0.1 thepiratebay.sx this way, when user types thepiratebay.sx in android device, it will be redirected to local host and will not let user to browse that added site in that list.

Related : How to Rename Files in Bulk using ES File Explorer File Manager

Modifying Hosts Files on Android Smartphones

You have modified the hosts file from your local drive of computer. Now you will have to overwrite the hosts file on your android system>etc>hosts.  So open command prompt and type the following command to replace the old hosts file with modified host file.

adb push F:\hosts /system/etc/

So it will transfer the file from F drive of your computer and replace the old hosts file with modified one.

See, we have blocked Facebook.com from hosts file, so whenever user will type facebook.com from the browser, it will not open.

Android Edit Hosts File
Android Edit Hosts File

You can also use Hosts editor android app, which is available free on Google Play Store, if you don’t want to edit it through your computer. You can easily modify your android’s hosts file using that hosts editor android app.

Related : Best Website Blocker App – Use Without Rooting Your Device

Last Updated On: April 8, 2016

About Bhavesh Sondagar

Bhavesh Sondagar is editor in chief and webmaster of Theandroidportal Blog. You may feel free to contact us for reviewing your product using this contact form.

9 comments

  1. Does not work: read only device!

    • how you’ve managed to get rid of read only device?

      • Hi Traiii,
        You can root your smartphone to get rid of read only device.

        • Hi,

          Kindly guide me how to root the android smartphone to get rid of read only device, so that i can edit the host file.

          I have followed the steps explain in the above but it failed due to read only access.

          Kindly guide me on this.

          Thanks,

          • hi suresh,
            can you tell me your device’s model number? so that we can get best possible solution to root your smartphone.

          • Hi Bhavesh Sondagar,

            Kindly note the model no of my mobile device.

            samsung
            Device name: Galaxy J7
            Model number: SM-J7OOF
            Android version: 5.1.1

            Let me know for more details if required.

            Thks

  2. you should have mentioned the prerequisite: “rooted device” in the first sentence.

  3. I have to thank you for the efforts you’ve put in writing this blog.

    I really hope to see the same high-grade content from you later on as
    well. In truth, your creative writing abilities has motivated me to get my very own site now 😉

  4. Hi sir… I cant open my gooleplaysevices also goole apps store. My device is already been rooted . but i cant edit nor delete that “host file” ialways got the message “file is read only.. Thanks in advance

Home > How To > How To Modify Hosts File & Block Websites On Android [rooted device]