Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hostnamectl command not working #2380

Closed
mw7301 opened this issue Jul 29, 2017 · 13 comments
Closed

hostnamectl command not working #2380

mw7301 opened this issue Jul 29, 2017 · 13 comments

Comments

@mw7301
Copy link

mw7301 commented Jul 29, 2017

  1. Issue Title
    1.1 hostnamectl command not working

  2. Windows version/build number
    2.1 Microsoft Windows [Version 10.0.16251.0]

  3. Steps required to reproduce
    3.1 issue command hostnamectl at the command line

  4. Terminal output
    4.1 Failed to get D-Bus connection: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory

  5. Expected behavior
    5.1 Example
    dev@u16dev:~$ hostnamectl
    Static hostname: u16dev
    Icon name: computer-vm
    Chassis: vm
    Machine ID: e61618a42c664b82a08d5055a6057ad9
    Boot ID: eb7b7e88909e47eb87c8f1c1f78517ac
    Virtualization: vmware
    Operating System: Ubuntu 16.04.2 LTS
    Kernel: Linux 4.9.0-040900-generic
    Architecture: x86-64

  6. End Report

@fpqc
Copy link

fpqc commented Jul 29, 2017

Hostnamectl goes through hostnamed, which is one of the components of systemd, ergo it will fail to work.

You should be able to change it by hand with /etc/hostname

@heldchen
Copy link

I had no luck changing /etc/hostname, mostly due to the /etc/hosts file being autogenerated using the windows hosts file. just changing /etc/hostname breaks sudo and other commands.

I ended up running the following in a startup script run as root:

HOST=devbox
grep -P -q "127.0.1.1\t$HOST" /etc/hosts || sed -i "s/127.0.1.1\t/127.0.1.1\t$HOST /" /etc/hosts
hostname $HOST

@fpqc
Copy link

fpqc commented Jul 30, 2017

You can remove the line at the top of the hosts file to stop automatic generation

@heldchen
Copy link

that might work for the legacy version, but since the Ubuntu store version, the /etc/hosts header is different:

# This file is automatically generated by WSL based on the Windows hosts file:
# %WINDIR%\System32\drivers\etc\hosts. Modifications to this file will be overwritten.
127.0.0.1       localhost
...

I have verified that at least in build 16251 the /etc/hosts and /etc/hostname are regenerated even when those header lines are removed.

@mw7301
Copy link
Author

mw7301 commented Jul 30, 2017

I wasn't using hostnamectl to change the hostname, I was just using it for the information about the system that it displays. Are you saying that since its part of systemd it will not work? If so why is that?

@heldchen
Copy link

@mw7301 there is no systemd running in WSL

@therealkenc
Copy link
Collaborator

I was just using it for the information about the system that it displays

Which specifically are you looking for?

@mw7301
Copy link
Author

mw7301 commented Jul 31, 2017

I was just filing a bug report since it doesn't work

@therealkenc
Copy link
Collaborator

I was just filing a bug report since it doesn't work

In that case it's a dupe of #1579 (message), #994 and friends. Same mode of failure: socket /var/run/dbus/system_bus_socket: No such file or directory. Once systemd lights up you will have hostnamectl.

@benhillis
Copy link
Member

Agreed, this is a duplicate.

@harryqt
Copy link

harryqt commented Jan 18, 2020

I ended up running the following in a startup script run as root:

@heldchen can you tell what exactly you did? I tried your commands on /etc/rc.loal and crontab to sh script but nothing worked for me.

@heldchen
Copy link

I have a /etc/init.d/wsl-init script that is triggered upon first login by some bash profile script. requires the user to have sudo rights so is not that great. the code (among other stuff) that is executed is:

        HOST=devbox
        grep -P -q "\t$HOST" /etc/hosts || sed -i "s/127.0.1.1\t/127.0.1.1\t$HOST /" /etc/hosts
        hostname $HOST
        echo "$HOST" > /etc/hostname

@flybyray
Copy link

        hostname $HOST

This might not work on each distribution. AlmaLinux from Windows Store does not provide it by default. The image is distributed with hostnamectl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants