Android - How to edit 'etc/hosts' file in non-rooted phone?

Unless I missed something, that is not possible. Without root access only the mechanism of flashing an update (via recovery or OTA) can modify /system. To be accepted, such an update archive must be signed with the same key as the ROM – which is something only the developer of the ROM (here: the LOS team) can do.

There might be a way via a custom recovery which lets you edit all file systems directly (see e.g. twrp). But without knowing what device it is, it cannot be said if a matching recovery exists (you can check that in the Devices section of their website for official images, and search XDA for unofficial ones). Apart from that, it's either rooting the device or not editing any file within /system.


It is possible to use a VPN profile* to affect hostname resolution. There are a number of apps now available on the Play Store that provide a convenient way to do this, such as Hosts Go. Note that, since this technique requires the use of a VPN profile, you won't be able to use an actual VPN in conjunction with this technique.


*As of Android 4.0 (API Level 14) — https://developer.android.com/guide/topics/connectivity/vpn


On non-rooted phone you cannot actually edit hosts file but it's possible to use VPN apps like Virtual Hosts or Personal DNS Filter (both are open-source, I've no affiliation with either) which intercept DNS traffic and look up a custom hosts file before making queries to configured upstream DNS server.

Or if bootloader is unlockable, editing hosts file is possible through custom recovery.

For more alternatives see: How to always resolve a domain name to a fixed IP without rooting?

Tags:

Hosts