Okay, I know this is very old school. But still, I bet not many people have tried this. You can use this method to block ad serving sites on your cell (without any software), or to block Facebook on your friends cell or to block whichever site you want on any Android :D.
The method is same as what we saw here for windows machines. Only difference is, this time it will be on Linux So the path to hosts file will be different. First of all, you will have to root your Android. If you haven’t done this yet then go here or search Google and do it now ;). After this download any good file explorer from play store. Now navigate to the /system/etc/ and look for hosts file. Open this file with any text editor. Something like this will already be there in the file.
127.0.0.1 localhost ::1 localhost
The first column is for IP address and the domain name goes in the second column. So when you type localhost in your browser it automatically redirects it to 127.0.0.1. In simple words, for any domain resolution request your device will first check hosts file for resolution and if it is not there then it will go to DNS server. So if you add anything here then it will not go to DNS server for name resolution.
You can try this on your friends rooted Android and watch him jumping on his phone after few hours :D. Add below entry to his phone’s hosts file, save it and restart the phone.
This IP address is of Google, so when your friend types facebook.com in his browser, he will be redirected to Google. If you want to block it then just replace the Google IP with 127.0.0.1 and as there will be no site hosted at this address, he will be greeted with “Webpage not available” message every time ;).
Obviously, Facebook has too many sub-domains and domains, so if you want to block it completely then you will have to list all of them in this file. You can use this trick to block any website you want.
To unblock any site, just reverse the process. Delete its entry from the hosts file, save it and restart the phone.