If you use an Android device and want to know how to control and manage what websites your children visit, you don’t have to purchase a blocking app from the Play Store. Note – you can only perform what is mentioned here if your device is rooted, so for the benefit of readers, I will assume your device is already rooted. What is rooting?
When the term ‘rooting’ is used on Android, it refers to allowing users obtain privileged control (known as “privilege escalation’) of the Android device. This in effect means allowing the user to run privileged commands on the Android operating system. Rooting a device allows users to unlock the hardware i.e. bootloader code (which is open source ;)) to install an updated OS version, or installing a custom flash ROM.
Rooting is something I have done on many occasions and the main reason for doing it has been to access admin-features to for example look at stopping a process that is draining battery power. Another reason I like to root is to remove carrier ‘bloatware’ – these are the apps that are carrier specific, you never use, but affect the performance of your device. Another reason to root is that I can backup the entire phone – you cannot do this if the phone isn’t rooted.
Anyway enough chat on Android rooting, let’s get down to showing you how to block websites (which uses ‘name-to-IP lookups’) on a rooted device (I’ve assumed in this tutorial that you a rooted device) using the Android custom hosts file. Here is the simplest method of editing the Android hosts file on your device using a PC running Windows 7 Professional SP1:
- Download and install Android SDK Android Debug Bridge (ADB) – Download the ADB executable zip file* into your download folder
- Unzip the file containing the ADB (Android Debug Bridge) executables into your download folder – called “ac-platform-tools*
- Enable USB debugging on your Android device – go to Settings > Developer options
- Test ADB and install the appropriate device drivers – you can do this by connecting your Android device to your computer via USB. Windows TIP: Type ‘cmd’ in Start and click this to open the command tool and type ‘adb devices’ and hit return. You should now see your device (see last paragraph)
- Download the host file from your Android device for editing typing > adb pull /system/etc/hosts C:\Users\<your name>\hosts (also make a backup of your original hosts file) – The bold text is where the file will be copied to on your PC – you can choose this
- Navigate to where you downloaded the hosts file and open it in a text editor (i.e. notepad)
- You can now edit each domain entry and add the local host IP address 127.0.0.1 to each individual websites or ad to block it
- Next you need to upload the edited hosts file back to your Android device. Type > adb push C:\Users\<your name>\hosts /system/etc/ – The bold text is where the file will be copied from on your PC – you can choose this
- That’s it, you are now done!
*You don’t need the Android SDK, so this will save you lots of time.
We experienced problems with ADB not finding our Samsung Galaxy S3 on our Windows 7 lab machine as well as port 5037 in CLOSE_WAIT or TIME_WAIT states. We used a Windows application called TCPVIEW to locate the hung socket. Once this was done the ADB server was back working for us.
Safe surfing folks!