We have moved to a new Sailfish OS Forum. Please start new discussions there.

adblock via /etc/hosts on XA2/AlienDalvik v8

asked 2019-11-01 16:11:00 +0300

jollajo gravatar image

updated 2019-11-27 16:57:14 +0300

jiit gravatar image

To block unwanted ads I've always modified /etc/hosts with the list given by winhelp2000.com. To also block the ads in Android apps we also need to modify the hosts file on the android side. For Andorid 4.4 (Jolla 1/C, Xperia X) you could copy this to /system/etc/hosts and /opt/alien/system/etc/hosts.

On the newer Version of AlienDalvik that runs on XA2 the file is only accessible within the lxc container and unfortunately the filesystem is readonly there. Is there a way to modify that file without unpack-modify-repack the filesystem (I don't dare to do so.)? Is there another location we could keep the list?

Do you have any other idea?

edit retag flag offensive close delete

3 Answers

Sort by » oldest newest most voted

answered 2019-11-02 10:07:55 +0300

lethe gravatar image

You can override the android hosts file without re-packing the filesystem image by modifying the LXC config.

Simply edit the file /var/lib/lxc/aliendalvik/extra_config as root and add following line:

lxc.mount.entry = /etc/hosts system/etc/hosts none bind,create=file 0 0

This has the added benefit, that it should survive aliendalvik updates (and if it doesn't, it is at least easier to restore).

edit flag offensive delete publish link more


Thanks, this worked for me on my Xperia XA2 Ultra with SFOS

Direc ( 2020-05-17 11:02:13 +0300 )edit

answered 2019-11-01 20:00:19 +0300

olf gravatar image

updated 2020-09-13 04:33:25 +0300

There iwas no need to copy /etc/hosts to the Android side for the AOSP 4.x based AlienDalviks (Jolla 1, Jolla C, Xperia X) for ad-blocking:
Simply use Defender to manage /etc/hosts, which is effective for Android apps, too.

While I have no AOSP 8 based AlienDalvik, I wonder why the lxc-containerisation would change that.
Can you please check with Defender.

Edit (2020-09-13): Meanwhile Defender turned out to prevent Xperia 10s and XA2s from booting and it has become unmaintained for long. Use this answer for these and any other device with the AOSP8-based AlienDalvik.

edit flag offensive delete publish link more



This won't work on AlienDalvik 8, as the android environment is completely separated from the host within its LXC container. I think previous AlienDalvik releases used the DNS server listening on provided by connman (hence /etc/hosts worked for android). Since from within the LXC container AlienDalvik has no access to that server, it probably uses the DNS server IP retrieved from DHCP, thus /etc/hosts no longer works (the container has its own namespace and loopback interface, so are not connected on the host & android system).

lethe ( 2019-11-02 09:55:21 +0300 )edit

just checked a few websites full of ads and they look very similar (only few or no ads) on native and Android browsers.

So it seems that Android apps are influenced by native /etc/hosts

I was hoping to get rid of ads within Android apps but it seems they're directly fed by google.

jollajo ( 2019-11-02 23:15:39 +0300 )edit

My results of (admittedly very limited) testing on my XA2 were:

  • editing /etc/hosts did nothing for android apps
  • replacing /system/etc/hosts by repacking system.img worked both for blocking browser as well as in-app ads (served by google)
  • editing the LXC config as described above worked just as well
lethe ( 2019-11-04 02:25:18 +0300 )edit

Well @lethe,

Can you please check with Defender.

olf ( 2019-11-04 21:48:46 +0300 )edit

That's what I used, however I do not see why that would matter...

Defender doesn't do any black magic, all it does is gather blocklists from multiple source, merge them and write them to /etc/hosts, /system/etc/hosts & /opt/alien/system/etc/hosts.

The last path will be skipped on AlienDalvik 8, since it does not exist and the second one doesn't matter (at least in my test).

lethe ( 2019-11-05 10:55:51 +0300 )edit

answered 2019-11-01 19:45:21 +0300

kan_ibal gravatar image

Check Dnscrypt on Sailfish. There is a possibility to set Blacklist to block ads at dns query level.

edit flag offensive delete publish link more
Login/Signup to Answer

Question tools



Asked: 2019-11-01 16:11:00 +0300

Seen: 1,351 times

Last updated: Sep 13 '20