Page 1 of 1

How to modify hosts file?

Posted: 29 Sep 2020 23:47
by aximili
I want to apply a certain hosts file (that I have on my SD card) when I open a particular app, and restore the original hosts file on exit.
I thought Automagic would be the perfect tool to do it.

My idea was:
App launch -> Copy/rename /etc/hosts to /etc/hosts1 -> Copy /emulated/0/my-hosts to /etc/hosts
App exit -> Rename /etc/hosts1 back to /etc/hosts

I tried using "Move files" hoping to rename /etc/hosts to /etc/hosts1 but it didn't even work (/etc/hosts1: open failed: EROFS (Read-only file system))
Could someone help me please?

(I found this Tasker task that seems to modify hosts file but couldn't find an Automagic one https://forum.xda-developers.com/u/task ... e-t3659602)

Re: How to modify hosts file?

Posted: 30 Sep 2020 20:49
by Micky Micky
Hello

I don't know how to link you to my earlier posts, but if you search this forum for "Delete files in root folder" this may shed some light on your problem.

Hope this helps

Micky

Re: How to modify hosts file?

Posted: 01 Oct 2020 11:17
by aximili
Thank you Micky it is definitely useful.

I tried this

Code: Select all

mv /etc/hosts /etc/hosts1
and I seem to run into the same error:
stderr=mv: bad '/etc/hosts': Read-only file system

I am now trying to make sense of Desmanto's reply to you about mounting as rw...

Code: Select all

mount | grep /etc
That produced nothing in the stdout. I guess it is another question, thanks Micky!

Re: How to modify hosts file?

Posted: 01 Oct 2020 20:11
by Micky Micky
Hello

"I couldn't mount /system as rw but it worked without the word system."

This might help. It did for me.

Good luck

Micky

Re: How to modify hosts file?

Posted: 01 Oct 2020 23:20
by aximili
Thank you Micky for trying to help me! So I've tried this:

Code: Select all

mount -o rw,remount /system
That gave me mount: '/system' not in /proc/mounts

Then I tried this:

Code: Select all

mount -o rw,remount
That seems successful? (nothing in stderr)

But after that, trying

Code: Select all

mv /etc/hosts /etc/hosts1
still gave me mv: bad '/etc/hosts': Read-only file system :'(

Re: How to modify hosts file?

Posted: 01 Oct 2020 23:27
by Hit
Does your phone have root access?
And enable this: Root functions (Experimental)?

Re: How to modify hosts file?

Posted: 01 Oct 2020 23:55
by aximili
Yes I had already have Root functions enabled, thanks Hit.
AdAway is working fine on my phone (it writes to the hosts file, I can see the hosts file entries changing when I use AdAway)