1

I'm running an arch system with KDE4/Plasma, wpa_supplicant, networkmanager, systemd ...

# cat /proc/version  
Linux version 5.0.0-arch1-1-ARCH (builduser@heftig-18825) (gcc version 8.2.1 20181127 (GCC)) #1 SMP PREEMPT Mon Mar 4 14:11:43 UTC 2019

The content of my /etc/hostname reads localhost. After boot, the shell command hostname now outputs localhost. More precisely:

# hostnamectl 
   Static hostname: localhost
Transient hostname: localhost.localdomain
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 7e0a101cd2f0406497a6e4354fc9b3b7
           Boot ID: a1424a0995da4e84b1e55b7f79df957e
  Operating System: Arch Linux
            Kernel: Linux 5.0.0-arch1-1-ARCH
      Architecture: x86-64

When I turn on WiFi, networkmanager connects to a WiFi network and then the hostname changes. For instance:

# hostnamectl 
   Static hostname: localhost
Transient hostname: localhost.localdomain
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 7e0a101cd2f0406497a6e4354fc9b3b7
           Boot ID: a1424a0995da4e84b1e55b7f79df957e
  Operating System: Arch Linux
            Kernel: Linux 5.0.0-arch1-1-ARCH
      Architecture: x86-64

The shell command hostname now outputs localhost.localdomain instead of localhost.

As a consequence, the KDE lock-screen cannot be unlocked and I cannot start any X applications from the terminal in KDE (or any other desktop). A typical error message is this:

$ gvim
Invalid MIT-MAGIC-COOKIE-1 keyE233: cannot open display

When I issue hostnamectl set-hostname localhost as root, the behavior resumes to normal.

In some other WiFis, the hostname after connect is not localhost.localdomain but something even more random (it seems to be a hostname determined by the WiFi provider, mostly in big corporate networks). Why does a WiFi provider have the power to set my hostname? Can this be changed somehow?

  • 1
    That is a DHCP "feature" and not from Wifi per se. Depending on the DHCP daemon, some of those configurations can be ignored. TDLR It is a feature, not a bug. But it is not supposed to interfere with X. – Rui F Ribeiro Apr 18 at 16:47
  • Ah thank you! What, by the way, does TDLR mean? Is it possible to configure DHCP in a way that it doesn't change the hostname? – LaTechneuse Apr 19 at 11:57
2

Several potential ways to fix it. It could be that you have a localhost entry in /etc/hosts (like everything else on the planet) but you do not have a localhost.localdomain entry. Adding one, also pointing to 127.0.0.1, may be a fix for your "at home" issue - but not for the "random" seeming ones you get on the "large corporate" networks.

The "better" option though is to check your dhcp client configuration. In /etc/dhcp/dhclient.conf (or it may be dhcpcd.conf depending on distro) look for the request line(s) -

request subnet-mask, broadcast-address, time-offset, routers,
    domain-name, domain-name-servers, domain-search, host-name,
    dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
    netbios-name-servers, netbios-scope, interface-mtu,
    rfc3442-classless-static-routes, ntp-servers;

And simply remove the host-name option.

1

Ivanivan's answer (tuning dhcpcd.con), though plausible, didn't work in my case. So I suspect it is not about DHCP. I stumbled upon this post: Prevent dhcpcd from setting hostname

Which gave the my problem is not about DHCP but about NetworkManager. Adding the following to /etc/MetworkManager/NetworkManager.conf solved the problem to me:

[main]
plugins=keyfile 
hostname-mode=none 

See man 5 NetworkManager.conf for details on the hostname-mode option. Setting it to none prevents NetworkManager from setting a transient hostname which is what happened in my case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.