How to edit your hosts file on Fairphone


There are actually many good reasons you may want to update your hosts file.
For example:

  • Access some specific domain from a different IP than the public one,
  • Block ads
  • Prevent access from to some specific websites your phone
  • Etc etc etc

So, this is a short tutorial for advanced users with linux/unix background willing to modify the hosts file on your Fairphone.
I’m writing this quick guide so that anyone in the Fairphone community can use it, improve it and of course share it! :wink:

First, you need to have adb installed on your computer.

So, here’s how to do it on your Fairphone:
1- Enable USB Debugging in Developer Options

2- Connect your Fairphone through USB and check it is detected by running:

$ adb devices
List of devices attached
0123456789ABCDEF device

3- Retrieve the host file:

$ adb pull /system/etc/hosts .

You can then edit and modify the host file as you want it to be

4- Mount the filesystem as readwrite

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

5- Send the modified hosts file to you sdcard

$ adb push hosts /storage/sdcard0/Android/data

6- Copy the hosts file from your sdcard to where it´s supposed to be:

$ adb shell
$ su
$ cd /system/etc
$ cp /storage/sdcard0/Android/data/hosts .

7- Check your new hosts file content

$ cat hosts
$ exit
$ exit

8- IMPORTANT - Return the system as readonly:

$ adb shell
$ su
$ mount -o remount,ro /system
$ exit
$ exit

And you’re done!


Excellent -thank you. This way we don’t need any third party software.
BTW, how would you comment such softwares? I understand there are a couple of them here and there…