How to change the hosts file on android

AndroidHosts

Android Problem Overview


I have successfully rooted my Samsung Galaxy Mini (android 2.2.1) and thought, that I could change anything (as root usually can).

I would like to change the hosts file on the android, to include some local addresses. However, I still get the message that I do not have permission to do that. I tried following options:

  1. adb push /path/to/my/new/hosts /system/etc ... and I got the response Read-only file system.

  2. directly in the shell on the phone. But this didn't work either. I can do su in the console, but cannot change the file.

Isn't it strange, that as super user I am not allowed to change some files?

Android Solutions


Solution 1 - Android

You have root, but you still need to remount /system to be read/write

$ adb shell
$ su
$ mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

Go here for more information: Mount a filesystem read-write.

Solution 2 - Android

adb shell
su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

This assumes your /system is yaffs2 and that it's at /dev/block/mtdblock3 the easier/better way to do this on most Android phones is:

adb shell
su
mount -o remount,rw /system

Done. This just says remount /system read-write, you don't have to specify filesystem or mount location.

Solution 3 - Android

That didn't really work in my case - i.e. in order to overwrite hosts file you have to follow it's directions, ie:

./emulator -avd myEmulatorName -partition-size 280

and then in other term window (pushing new hosts file /tmp/hosts):

./adb remount
./adb push /tmp/hosts /system/etc

Solution 4 - Android

Probably the easiest way would be use this app Hosts Editor . You need to have root

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFilip MajernikView Question on Stackoverflow
Solution 1 - AndroidLeif AndersenView Answer on Stackoverflow
Solution 2 - AndroidPaulView Answer on Stackoverflow
Solution 3 - AndroiddsomnusView Answer on Stackoverflow
Solution 4 - AndroidbyroncorralesView Answer on Stackoverflow