# RESOLVED: hostname stopped working

## marinheiro

In the past I've always had a hostname in /etc/hostname, which would appear by the prompt in any terminals, etc. Now my hostname appears as 'unknown-[my mac address]'.

Looking at /var/log/messages, I find that systemd-hostnamed.service thinks there is an invalid parameter somewhere, but I don't know where it thinks it is:

```

Dec 14 09:25:23 localhost dbus-daemon[3052]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service'

Dec 14 09:25:23 localhost systemd[1]: Got message type=signal sender=org.freedesktop.DBus destination=org.freedesktop.systemd1 object=/org/freedesktop/DBus interface=org.freedesktop.systemd1.Activator member=ActivationRequest cookie=53 reply_cookie=0 error=n/a

Dec 14 09:25:23 localhost systemd[1]: Trying to enqueue job systemd-hostnamed.service/start/replace

Dec 14 09:25:23 localhost systemd[1]: Installed new job systemd-hostnamed.service/start as 1014

Dec 14 09:25:23 localhost systemd[1]: Enqueued job systemd-hostnamed.service/start as 1014

Dec 14 09:25:23 localhost systemd[1]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=JobNew cookie=223 reply_cookie=0 error=n/a

Dec 14 09:25:23 localhost systemd[1]: Starting Hostname Service...

Dec 14 09:25:24 localhost gnome-shell[3379]: GNOME Shell started at Mon Dec 14

2015 09:25:19 GMT+0000 (GMT)

Dec 14 09:25:25 localhost systemd[1]: About to execute: /usr/lib/systemd/systemd-hostnamed

Dec 14 09:25:25 localhost systemd[1]: Forked /usr/lib/systemd/systemd-hostnamed as 3486

Dec 14 09:25:25 localhost systemd[1]: systemd-hostnamed.service changed failed -> start

Dec 14 09:25:25 localhost systemd[1]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/systemd1/unit/systemd_2dhostnamed_2eservice interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=224 reply_cookie=0 error=n/a

Dec 14 09:25:25 localhost systemd[1]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/systemd/unit/systemd_2dhostnamed_2eservice interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=225 reply_cookie=0 error=n/a

Dec 14 09:25:25 localhost systemd[1]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/systemd1/job/1014 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=226 reply_cookie=0 error=n/a

Dec 14 09:25:25 localhost (ostnamed)[3486]: Failed at step NETWORK spawning /usr/lib/systemd/systemd-hostnamed: Invalid argument

Dec 14 09:25:25 localhost systemd[1]: Received SIGCHLD from PID 3486 ((ostnamed)).

Dec 14 09:25:25 localhost systemd[1]: Child 3486 ((ostnamed)) died (code=exited, status=225/NETWORK)

Dec 14 09:25:25 localhost systemd[1]: Child 3486 belongs to systemd-hostnamed.service

Dec 14 09:25:25 localhost systemd[1]: systemd-hostnamed.service: main process exited, code=exited, status=225/NETWORK

Dec 14 09:25:25 localhost systemd[1]: systemd-hostnamed.service changed start -> failed

Dec 14 09:25:25 localhost systemd[1]: Job systemd-hostnamed.service/start finished, result=failed

Dec 14 09:25:25 localhost systemd[1]: Failed to start Hostname Service.

Dec 14 09:25:25 localhost systemd[1]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/systemd1

interface=org.freedesktop.systemd1.Manager member=JobRemoved cookie=227 reply_cookie=0 error=n/a

Dec 14 09:25:25 localhost systemd[1]: Unit systemd-hostnamed.service entered failed state.

```

Trivial, but annoying in something that has always worked before...

Any ideas?

GrahamLast edited by marinheiro on Thu Dec 17, 2015 12:13 pm; edited 1 time in total

----------

## gordonb3

Hostname service takes the name from /etc/conf.d/hostname.

The content of this file should contain an entry as follows:

```
hostname="mymachine"
```

----------

## marinheiro

Thanks - hadn't noticed that. /etc/conf.d/hostname is actually there, created on December 8th (I guess I missed it by not paying enough attention during an emerge). However, it doesn't make any difference - the contents is there and correct, but apparently ignored.

Graham

----------

## Princess Nell

Are you using NetworkManager? You may need to set the hostname in the keyfile section.

----------

## Fitzcarraldo

If I recall correctly, if you're using systemd you need to use the hostnamectl command to set the hostname:

```
# hostnamectl set-hostname <hostname>
```

But the hostname also needs to be declared in /etc/hosts. Here's what works for me:

```
127.0.0.1       <hostname>      localhost.localdomain   localhost       <hostname>.localdomain

::1     <hostname>      localhost6.localdomain6 localhost6
```

And, if you're using NetworkManager, the hostname also needs to be declared in /etc/NetworkManager/NetworkManager.conf:

```
[main]

plugins=keyfile

[keyfile]

hostname=<hostname>
```

----------

## gordonb3

 *Fitzcarraldo wrote:*   

> But the hostname also needs to be declared in /etc/hosts.
> 
> 

 

Yes and no. Several services will in fact not start if hostname can not be resolved, but it doesn't really matter which way it is resolved. With systemd however this can be an issue because it tends to start everything in parallel so networking may in fact not be functional yet when a service is started that depends on it. Adding the entry to /etc/hosts fixes that.

The hostname should normally not be added to the localhost entry though, but to the real IP address. To make `hostname -f` work the first entry following the IP address should be the fully qualified name and then the hostname. e.g.

```
192.168.0.1    hostname.localdomain    hostname    [any alternate name]

```

----------

## marinheiro

The problem was indeed the NetworkManager configuration. Thanks to all of you! It turned out I didn''t have a NetworkManager.conf file at all, so I created one just for the hostname.

I don't like this very much though: given traditional locations for this value (/etc/hosts, /etc/hostname) what is the point of  duplicate (and potentially conflicting) value in two more configuration files, when the applications using that configuration could perfectly well pick the value up from the traditional files? 

Ah well, since I'm not doing the work I guess I shouldn't grumble - and this is a pretty minor problem.

While I'm here does anyone have any ideas about my loss of sleep function on closing the lid: https://forums.gentoo.org/viewtopic-t-1035256-highlight-.html

Thanks again

Graham

----------

## Fitzcarraldo

 *gordonb3 wrote:*   

> The hostname should normally not be added to the localhost entry though, but to the real IP address. To make `hostname -f` work the first entry following the IP address should be the fully qualified name and then the hostname. e.g.
> 
> ```
> 192.168.0.1    hostname.localdomain    hostname    [any alternate name]
> 
> ...

 

When I installed Gentoo I followed the Gentoo Handbook:

https://wiki.gentoo.org/wiki/Complete_Handbook/Configuring_the_system

 *Gentoo Handbook wrote:*   

> The /etc/hosts file is a small table the system uses to make immediate translations between hostnames and IP addresses. This file should at least contain one line:
> 
> 127.0.0.1       localhost
> 
> All other lines should be set under that line using the following syntax:
> ...

 

The trouble is, that doesn't work in my case. I have to use my laptop in a number of different offices (some using DHCP, others using various static addresses), hotels, public places and private homes. The lines I quoted earlier give me a consistent hostname (which is not 'localhost') on all those networks.

By the way, I forgot to mention in my previous post that, I also set the hostname in /etc/dhcp/dhclient.conf, as I found I also needed to do that on one company's network some years ago (I merge NetworkManager with USE="-dhcpcd dhclient"):

```
send host-name "<my hostname>";

supersede host-name "<my hostname>";
```

----------

## gordonb3

True. Some use cases can make it troublesome to implement this the right way. When using dhcp (both dhclient and dhcpcd support this) you can use a hook script to keep the content of /etc/hosts up to date similar to how /etc/resolv.conf is changed. When setting a static address through networkmanager, doesn't this add the corresponding entry to /etc/hosts? I don't use networkmaneger myself, but if it doesn't do this then I also don't see any point in using it.

----------

## Fitzcarraldo

 *gordonb3 wrote:*   

> When setting a static address through networkmanager, doesn't this add the corresponding entry to /etc/hosts? I don't use networkmaneger myself, but if it doesn't do this then I also don't see any point in using it.

 

Sorry, didn't notice your question before. No, NetworkManager does not add the static IP address to /etc/hosts. The static IP address is in /etc/NetworkManager/system-connections/<connection configuration file>. The connection configuration file for the applicable network can be edited directly or via a NetworkManager GUI front-end such as plasma-nm (KDE) or nm-applet (Xfce, etc.).

The hostname is specified by editing the file /etc/NetworkManager/NetworkManager.conf. Here is what it looks like on my Clevo W230SS laptop, for example:

```
[main]

plugins=keyfile

rc-manager=none

dhcp=dhclient

no-auto-default=*

[keyfile]

hostname=clevow230ss
```

'rc-manager=none' tells NetworkManager to manage /etc/resolv.conf itself instead of running resolvconf to do it. Here is what /etc/resolv.conf contains at the moment on the aforementioned laptop (as you can see below, I'm using a Wi-Fi Hotspot at the moment):

```
# Generated by NetworkManager

search VodafoneMobile.wifivodafonemobile.api

nameserver 192.168.0.1
```

----------

