How to modify hosts file?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
aximili
Posts: 23
Joined: 28 Jun 2018 11:14

How to modify hosts file?

Post by aximili » 29 Sep 2020 23:47

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)

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: How to modify hosts file?

Post by Micky Micky » 30 Sep 2020 20:49

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
Crude but it works.

User avatar
aximili
Posts: 23
Joined: 28 Jun 2018 11:14

Re: How to modify hosts file?

Post by aximili » 01 Oct 2020 11:17

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!
Last edited by aximili on 03 Oct 2020 10:41, edited 3 times in total.

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: How to modify hosts file?

Post by Micky Micky » 01 Oct 2020 20:11

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
Crude but it works.

User avatar
aximili
Posts: 23
Joined: 28 Jun 2018 11:14

Re: How to modify hosts file?

Post by aximili » 01 Oct 2020 23:20

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 :'(
Last edited by aximili on 03 Oct 2020 10:31, edited 1 time in total.

User avatar
Hit
Posts: 91
Joined: 20 Jan 2020 11:31

Re: How to modify hosts file?

Post by Hit » 01 Oct 2020 23:27

Does your phone have root access?
And enable this: Root functions (Experimental)?

User avatar
aximili
Posts: 23
Joined: 28 Jun 2018 11:14

Re: How to modify hosts file?

Post by aximili » 01 Oct 2020 23:55

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)

Post Reply