How do I fix my problem with hostnamectl command. It cannot connect to dbus

22,139

It looks like dbus package is missing.

Check if dbus package is installed or not using below command:

$ sudo dpkg -l | grep dbus
ii  dbus                           1.10.26-0+deb9u1                        amd64        simple interprocess messaging system (daemon and utilities)
ii  libdbus-1-3:amd64              1.10.26-0+deb9u1                        amd64        simple interprocess messaging system (library)

If dbus package is installed you will get output as above.

If output is blank then dbus package is missing. You can install the package using below command:

$ sudo apt-get install dbus

After installing the package you can check the status:

$ sudo systemctl status dbus.service dbus.socket
● dbus.service - D-Bus System Message Bus
   Loaded: loaded (/lib/systemd/system/dbus.service; static; vendor preset: enabled)
   Active: active (running) since Fri 2018-09-07 23:39:14 EDT; 10s ago
     Docs: man:dbus-daemon(1)
 Main PID: 451 (dbus-daemon)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/dbus.service
           └─451 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation

● dbus.socket - D-Bus System Message Bus Socket
   Loaded: loaded (/lib/systemd/system/dbus.socket; static; vendor preset: enabled)
   Active: active (running) since Fri 2018-09-07 23:39:14 EDT; 10s ago
   Listen: /var/run/dbus/system_bus_socket (Stream)
Share:
22,139
Bon Ami
Author by

Bon Ami

Updated on September 18, 2022

Comments

  • Bon Ami
    Bon Ami over 1 year

    I am running Debian 9.4. hostname works.

    $ sudo strace -f hostnamectl
    ...snipped...
    connect(3, {sa_family=AF_UNIX, sun_path="/var/run/dbus/system_bus_socket"}, 33) = -1 ENOENT (No such file or directory)
    ...
    
    Failed to create bus connection: No such file or directory
    

    UPDATE: here are more information:

    $ sudo systemctl status dbus.service dbus.socket
    Unit dbus.service could not be found.
    Unit dbus.socket could not be found.
    
    $ ps -p 1 
    PID TTY          TIME CMD
    1   ?        00:00:47 systemd
    
    $ sudo systemctl list-unit-files --state=running
    0 unit files listed.
    
    $ sudo systemctl list-unit-files --state=enabled
    ...snipped...
    26 unit files listed.
    
    • Rui F Ribeiro
      Rui F Ribeiro over 5 years
      Have you tried restarting dbus
  • Brian Thomas
    Brian Thomas over 4 years
    i had same issue with hotnamectl, i also needed to install dbus. Why was it missing in the first place is a better question. Can some kind of update cause that? wierd.
  • Jeremy Davis
    Jeremy Davis about 4 years
    dbus is non-essential service so depending on your setup, it may not have been installed. Anything that needs it should install it as a dependency. IMO systemd hostnamectl should ideally fallback to gathering the info in an alternate way if dbus is not available or at least give a better error message to make it clear that it doesn't work without dbus.