Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
RESOLVED: hostname stopped working
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
marinheiro
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jan 2004
Posts: 140

PostPosted: Mon Dec 14, 2015 10:01 am    Post subject: RESOLVED: hostname stopped working Reply with quote

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:

Code:

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?

Graham


Last edited by marinheiro on Thu Dec 17, 2015 12:13 pm; edited 1 time in total
Back to top
View user's profile Send private message
gordonb3
Apprentice
Apprentice


Joined: 01 Jul 2015
Posts: 185

PostPosted: Wed Dec 16, 2015 3:33 pm    Post subject: Reply with quote

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

The content of this file should contain an entry as follows:
Code:
hostname="mymachine"
Back to top
View user's profile Send private message
marinheiro
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jan 2004
Posts: 140

PostPosted: Wed Dec 16, 2015 7:27 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Princess Nell
l33t
l33t


Joined: 15 Apr 2005
Posts: 916

PostPosted: Wed Dec 16, 2015 11:07 pm    Post subject: Reply with quote

Are you using NetworkManager? You may need to set the hostname in the keyfile section.
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2034
Location: United Kingdom

PostPosted: Thu Dec 17, 2015 10:27 am    Post subject: Reply with quote

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

Code:
# hostnamectl set-hostname <hostname>

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

Code:
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:

Code:
[main]
plugins=keyfile

[keyfile]
hostname=<hostname>

_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC udev elogind & KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
gordonb3
Apprentice
Apprentice


Joined: 01 Jul 2015
Posts: 185

PostPosted: Thu Dec 17, 2015 11:04 am    Post subject: Reply with quote

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.
Code:
192.168.0.1    hostname.localdomain    hostname    [any alternate name]
Back to top
View user's profile Send private message
marinheiro
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jan 2004
Posts: 140

PostPosted: Thu Dec 17, 2015 12:13 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2034
Location: United Kingdom

PostPosted: Thu Dec 17, 2015 4:31 pm    Post subject: Reply with quote

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.
Code:
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:

<ip address> <fully qualified hostname> <aliases>

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"):

Code:
send host-name "<my hostname>";
supersede host-name "<my hostname>";

_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC udev elogind & KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
gordonb3
Apprentice
Apprentice


Joined: 01 Jul 2015
Posts: 185

PostPosted: Fri Dec 18, 2015 10:23 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2034
Location: United Kingdom

PostPosted: Wed Jan 20, 2016 7:52 am    Post subject: Reply with quote

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:

Code:
[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):

Code:
# Generated by NetworkManager
search VodafoneMobile.wifivodafonemobile.api
nameserver 192.168.0.1

_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC udev elogind & KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum