On my Android-based device I need to block access to all websites except ones are in a whitelist. I know that on desktop Windows I can list allowed hosts in the hosts file and then switch the DNS in the network adapter from automatically obtained to 127.0.0.1
. And now I can access only websites from the hosts file.
I've tried the same thing by adding allowed hosts in the system/etc/hosts
file on Android and then I've added the line
new_domain_name_servers="127.0.0.1 $new_domain_name_servers"
to the beggining of the file /etc/dhcpcd/dhcpcd-hooks/20-dns.conf
as described by the link.
And then I've restarted my device.
But I still can access all websites, so the solution doesn't work. And even if I just add a website to be resolved as 127.0.0.1 in the hosts file and clear browser cache, the website is still opened.
PS: I'm interested only in a solution which could be done on rooted device only (Android 4.0.4)
iptables
rules are not saved anywhere. You need to apply the rule(s) on every boot. Then blocking will definitely work. – Irfan Latif Jan 17 '20 at 19:26/etc/init
to execute some commands on every boot. – Irfan Latif Feb 01 '20 at 19:55/etc/init
and then reboot my device, the file automatically will run the rules again without any manual actions? – stckvrw Feb 07 '20 at 15:27