# [SOLVED]I don't understand transient hostnames

## beguiledfoil

So, this is a poor question, and I'm sorry. I'll do my best to make it productive and keep it short.

I'm running a systemd based system for the first time and I'm having an issue with my hostname. Basically, when I connect to (some) networks the network assigns me a transient hostname. This transient hostname seems to completely break everything with my desktop manager (KDM). I have to log out, and then log in with the new transient hostname (which is presumably assigned shortly after I log in and network manager connects to the network).

Is this expected? I have set my hostname as described in the handbook and the systemd wiki page.

How do I make my hostname *never* change based on dhcp crap?Last edited by beguiledfoil on Thu Sep 11, 2014 6:06 am; edited 1 time in total

----------

## Fitzcarraldo

Are you using NetworkManager, by any chance? I use OpenRC rather than systemd, but you can tell NetworkManager to use a persistent hostname by editing the file /etc/NetworkManager/NetworkManager.conf and specifying the hostname. Here is what I have in mine:

```
[main]

plugins=keyfile

dhcp=dhcpcd

[ifnet]

managed=true

auto_refresh=false

[keyfile]

hostname=meshedgedx
```

You'll notice that I'm using dhcpcd. Well, strictly speaking, NetworkManager is using dhcpcd. If I (NetworkManager, really) were using dhclient, I'd have declared dhcp=dhclient in the file instead.

----------

## beguiledfoil

Thanks so much for the reply. I don't have a NetworkManager.conf in that location. Should I create it? I'm a little worried that it won't be used as there are other references to a NetworkManager.conf that should live in /etc/dbus-1/system.d/. The version of NetworkManager.conf that lives in /etc/dbus-1/ is also, apparently meant to be XML.

I'm really tempted to just go back to openrc. I adopted systemd because it seemed inevitable, but the fact that I've managed to make my desktop unresponsive (like, I can't even run a program) by misconfiguring my network is clearly complete insanity.

Edit: I think you're totally right about this being a misconfiguration of NetworkManager on my part. My /etc/resolv.conf has some nameserver stuff and a comment that it was "Generated by NetworkManager". My current best idea is that I need it to not generate nameserver stuff (which is maybe what you're suggesting)  :Smile: 

----------

## Fitzcarraldo

I'm not sure what you're doing, but NetworkManager takes care of everything in my case. Anything special can be done using NetworkManager Dispatcher (e.g. I use NetworkManager Dispatcher to insert "options single-request" in /etc/resolv.conf because my ISP does not support IPv6 and my home router does not handle IPv6 requests correctly, but that's another story).

I know very little about systemd configuration, but, according to the Arch Wiki article on NetworkManager, you can force a persistent hostname in the same way that I'm doing it on my Gentoo installation with OpenRC, namely to do as I wrote in my previous post. Have a look at the Arch Wiki article which explains it: https://wiki.archlinux.org/index.php/NetworkManager#Hostname_problems

----------

## UberLord

Speaking solely for dhcpcd, dhcpcd will set the hostname if the DHCP message supplies one and the hostname is currently unset.

What does this mean in real terms?

Ensure that whatever statically configures the hostname runs before dhcpcd.

The same rule applies to dhclient as well, NetworkManager uses them both but I think it controls the hostname.

----------

## beguiledfoil

Great suggestions folks. I've done a few things that may or may not be making a difference:

1.  Added UseHostname=false to /etc/systemd/network/10-dhcp.network Full instructions here

2.  Updated my /etc/hosts file to include '.localdomain':

127.0.0.1 my_real_hostname localhost.localdomain localhost

I'll report back if this has finally fixed it. A race condition between whatever is setting the hostname statically and NetworkManager/dhcpd would be my worst nightmare. No idea what is setting the hostname statically...

----------

## beguiledfoil

I think everything is working thanks to the arch wiki page that Fitzcarraldo linked me to.

Specifically, I ended up adding a /etc/NetworkManager/NetworkManager.conf that contains the following lines:

[keyfile]

hostname=your_hostname

Where your_hostname is my hostname. My hostname is now written in 3 places (/etc/hosts, /etc/hostname, and /etc/NetworkManager/NetworkManager.conf). Oh, and I have some random executable (hostnamectl) sitting on my system doing a seemingly poor job of 'controlling' my hostname.

On a related note: If anyone knows of developers that are actively maintaining/improving openrc or are in any way ensuring that systemd remain optional please link me to their paypal(s)...

----------

## UberLord

 *beguiledfoil wrote:*   

> On a related note: If anyone knows of developers that are actively maintaining/improving openrc or are in any way ensuring that systemd remain optional please link me to their paypal(s)...

 

They don't require paypal as such. I'm not involved in OpenRC active development these days - it does what I set out to do at the time.

However, what the team really needs is more developers!

I do have a wishlist though, but I only really work on dhcpcd and related parts right now, although I have submitted two OpenRC patches recently .... heh.

----------

## Fitzcarraldo

For what it's worth, OpenRC causes me absolutely zero trouble. It just works. Reliably. And I like its features, such as local.d which enable me to do what I want to do. Perhaps my needs are not as sophisticated as some people's, but OpenRC does everything I need and no doubt more.

I have written only a handful of OpenRC init scripts in my time, but they were easy to knock out and worked. Ironically, one of them was to implement, just for the fun of it, Lennart Poettering's and Vivek Goyal's userspace alternative using cgroups to the so-called "200 Lines Kernel Patch That Does Wonders" back in 2010 (my post Re: Magical Patch!! in the Sabayon Linux forums referred).

So thank you for creating it, Roy!

----------

## UberLord

 :Embarassed:   :Embarassed:   :Embarassed:   :Embarassed:   :Embarassed:   :Embarassed: 

----------

