Is there any way to block access to a particular website through the stock Android browser?
If you have root, you can mount the systems partition as editable and edit the hosts file and set the site in question to redirect to 127.0.0.1. This is somewhat complicated voodoo, however, and I wouldn't recommend it if you don't know what I'm talking about already.
However if you don't want to do this manually and have rooted your phone, the app Hosts Editor is a nice little single purpose utility just for this.
If you're up for the voodoo, and have ADB installed:
From the terminal invoke the adb command with remount option otherwise you will get "failed to copy 'hosts' to '/system/etc/hosts': Read-only file system".
In the terminal pull the default hosts file from /system/etc/hosts or /etc/hosts which is the symlink of the file not only for backup purpose but also to get the file to modify.
adb pull /system/etc/hosts <path to pull hosts file to>
Modify the file according to your needs. (eg) 127.0.0.1 www.somewebsite.com
Push the file back to the phone:
adb push <path you pulled hosts file to>/hosts /system/etc/
That's it. You can check it out from the shell:
adb -e shell
The simplest way to block access to a website is by adding that domain name to
hosts file as mostly DNS resolvers honor that file. But it's not possible to edit
/etc/hosts without rooting Android device. Here are a few options you can go with on unrooted device:
- Use a VPN app which intercepts DNS traffic and looks up a custom
hostsfile before making queries to configured upstream DNS server.
- Run a DNS server; they can be configured to return a predefined IP address for a specific name. For instance if using
address=/xyz.com/0.0.0.0to “dnsmasq.conf”. Or on
xyz.com 0.0.0.0to “cloaking-rules.txt”.
- Configure phone to use a proxy or VPN and then add the entry
hostsfile on proxy server or run a local DNS server on VPN server.
- If bootloader is unlockable, edit
hostsfile from custom recovery.
For more details see: How to always resolve a domain name to a fixed IP without rooting?