Writing to /etc/hosts

I wrote a hosts-file switcher https://github.com/pbek/hswitch that generates an /etc/hosts file. It needs to be ran as root (which doesn’t seem to work with the snapped version of hswitch) and needs to write to the hosts file. Is that reason enough to apply for classic confinement in the snap store or is there an other way? (The name of the snap is “hswitch” in the store.)

Cheers and thank you!

I don’t think we have an interface for this, but it sounds like the sort of thing that would be interesting to have.

I have a similar problem with https://github.com/pbek/lmdownload (a Linux Magazine PDF downloader for subscribers) where the user might want to download pdfs to other paths than the home directory…

that one’s addressable using portals, though

thanks, I will look that up

IMO, a ‘hosts-control’ interface makes since for this. It is sufficiently different from hostname-control. I’ll take a TODO to implement it for 2.35.

Btw, it could arguably be in network-control.

Great, sounds like a plan! Thank you! :slight_smile:

FYI, writing /etc/hosts is in 2.35 and master via the ‘network-control’ interface.

That’s wonderful news!
Does that mean I only have to add that plug to https://github.com/pbek/hswitch/blob/develop/build-systems/snap/snapcraft/snapcraft.yaml and I can write /etc/hosts?

Do you know when 2.35 will hit Launchpad?

And does the application need root privileges to write the hosts file?

Yes, interfaces will not change the file permissions, /etc/hosts as a file is only root writable, so you might need a little daemon that a userspace app can talk to or something like that to do the actual write operation as non-privileged user.

Thank you for explaining!

1 Like

@mvo can answer for sure, but the core snap from beta and edge both have 2.35. I think right now, edge might have the commit.

Thank you, @jdstrand!