is there a interface I could use to set the hostname from with in the snap ? I am trying to use
hostnamectl set-hostname <new-host-name> command from with in my snap but the operation is denied.
Time: Feb 25 22:46:23
Log: apparmor="DENIED" operation="dbus_method_call" bus="system"
path="/org/freedesktop/hostname1" interface="org.freedesktop.hostname1" member="SetPrettyHostname"
mask="send" name="org.freedesktop.hostname1" pid=26082 label="snap.testpal.core" peer_pid=26083
Today, there is no interface for this. The network-manager slot policy almost allows it, by allowing SetHostname. This interface isn’t for plugging snaps though.
If we added this we would probably want to allow the dbus call, using the
sethostname() syscall, writing /etc/hostname and making sure the ‘hostname’ command works as expected with
If this interface were separate, I imagine it should be called
hostname-control, and it would be manually connected by default. There is an argument to have it in the existing
I will add this to backlog. If someone wants to implement this for the short term, I suggest creating a PR with changes to
network_control_test.go) and then we can handle implementation details in the PR.
I’m looking at this now and opting for a separate
@dhoomakethu do note that if you use network-manager, you should be able to set the hostname via network-manager for the time being (ie, your snap plugs network-manager then your snap uses whatever DBus APIs network-manager exposes for setting the hostname).
Do I have to ship
hostnamectl along with my snap as is the case with
mmcli to set the hostname ?
You will not have to ship it yourself.
For any one coming here with the same problem.
nmcli general hostname <hostname> should do the trick. provided
network-manager is plugged.