# hostname is being changed by networkmanager (maybe?)*SOLVED*

## Budoka

Mods my apologies if this is the wrong subforum. Please move if necessary.

So for the past couple of weeks, I've been having a problem with my box. 

See here: https://forums.gentoo.org/viewtopic-t-1054136-highlight-.html

I now suspect this may be a problem caused by my localhost name being changed by "something" after the initial boot/login. But once again I am a little out of my depth.

Upon trial and error, I noticed that on initial boot hostname and .Xauthority contains the same information in them. 

```
localhost.localedomain
```

Then at some point hostname is changed to my laptop name and .Xauthority remains localhost.localdomain. When I logoff and login again hostname is changed to what is in .Xauthority so that they match and I can launch apps no problem. 

I think now I have isolated that it networkmanager changing my hostname to my computer name and .Authority is keeping the "correct" localhost.localedomain. This is because if I boot and don't connect to a network, Xauthority and localhost are the same. Once I connect to my wifi locahost becomes my laptop name.

The strange thing is I haven't made any changes to any of this that I am of aware of. I did an update and bam...broken. So what am I doing wrong. It must be something misconfigured I am just not sure what to do and a forum search left me scratching my head.

Anyway thanks for the help everyoneLast edited by Budoka on Fri Jan 20, 2017 12:54 am; edited 1 time in total

----------

## Logicien

With Openrc you can fix the hostname in /etc/conf.d/hostname. With Systemd you use the command hostnamectl to fix it. Whatever is you hostname, I think it is always associated with 127.0.0.1, a local network.

This IP address have localhost.localdomain as FQDN (Full Qualified Domain Name), but can be associated with several alias. So, if for example, localhost is an alias to localhost.localdomain, you can add an other alias for the hostname you have set, for example personalhostname and an other one who is the hostname that NetworkManager give to your machine, for example mymachine. In /etc/hosts you can have

```
127.0.0.1 localhost.localdomain localhost mymachine personnalhostname
```

So .Xauthority would be able to use any of the hostname actually in use. I think you can configure NetworkManager to use the hostname you want but /etc/hosts is you friend here.

----------

## Budoka

 *Logicien wrote:*   

> With Openrc you can fix the hostname in /etc/conf.d/hostname. With Systemd you use the command hostnamectl to fix it. Whatever is you hostname, I think it is always associated with 127.0.0.1, a local network.
> 
> This IP address have localhost.localdomain as FQDN (Full Qualified Domain Name), but can be associated with several alias. So, if for example, localhost is an alias to localhost.localdomain, you can add an other alias for the hostname you have set, for example personalhostname and an other one who is the hostname that NetworkManager give to your machine, for example mymachine. In /etc/hosts you can have
> 
> ```
> ...

 

Thank you for the reply. Please bear with me while I try to understand this. I am still confused. 

So in my case I am using openrc. /etc/conf.d/hostname is and has always contained 

```
hostname="localhost"
```

.

If I am reading correctly /etc/hosts is also correctly indicating localhost for 127.0.0.1.

 *Quote:*   

> # /etc/hosts: Local Host Database
> 
> #
> 
> # This file describes a number of aliases-to-address mappings for the for
> ...

 

Where I am confused is that 1-I haven't changed any of this and my machine has worked flawlessly for years. SO something has changed in an update. and 2- For my life, I can't figure what is picking up my laptop name and changing localhost to that. I suspect NM but am not really sure.

----------

## Logicien

The network can be configure from several sources. You have to know which network services are active and which service is configuring each network interface you have, Openrc (Netifrc) and/or NetworkManager, etc. Than you can know which service is changing the hostname. Have-you check the file /etc/conf.d/net ? Setting the hostname is a part of the network configuration.

----------

## Fitzcarraldo

I am using NetworkManager 1.4.0-r1 with dhclient on my laptop running Gentoo Stable, and the hostname ('myhostname') is specified in the following three files:

```
# cat /etc/NetworkManager/NetworkManager.conf

[main]

plugins=keyfile

rc-manager=none

dhcp=dhclient

no-auto-default=*

[keyfile]

hostname=myhostname
```

According to NetworkManager.conf(5) man page: 'This key is deprecated and has no effect since the hostname is now stored in /etc/hostname or other system configuration files according to build options.' but it does no harm to include it in NetworkManager.conf in any case (https://wiki.gentoo.org/wiki/NetworkManager#Hostname_problems).

```
# cat /etc/hosts

127.0.0.1 myhostname localhost

::1 myhostname localhost
```

```
# cat /etc/dhcp/dhclient.conf

send host-name "myhostname";

supersede host-name "myhostname";
```

Also, when using NetworkManager, other network management services must not be enabled (see https://wiki.gentoo.org/wiki/NetworkManager#OpenRC).

This works fine in my case.

EDIT: Just consulted this post in order to comment on a more-recent thread, and notice I forgot to mention above that I also have the hostname declared in /etc/conf.d/hostname:

```
# cat /etc/conf.d/hostname 

# Set to the hostname of this machine

hostname="myhostname"
```

/etc/conf.d/hostname was pointed out by both Logicien earlier in this thread, and khayyam later in this thread. Anyway, I'm adding it to this post now for my own future reference.

----------

## khayyam

 *Budoka wrote:*   

> So in my case I am using openrc. /etc/conf.d/hostname is and has always contained
> 
> ```
> hostname="localhost"
> ```
> ...

 

Budoka ... you missed the sections host and domain information, and the hosts file, in the handbook.

best ... khay

----------

## Budoka

 *khayyam wrote:*   

>  *Budoka wrote:*   So in my case I am using openrc. /etc/conf.d/hostname is and has always contained
> 
> ```
> hostname="localhost"
> ```
> ...

 

Thanks khay. You always come to my rescue. LOL

I am a little confused. I did do this when initially setting my system up. Are you indicating that I can't or it isn't ideal to set my hostname to localhost?

Part of what is difficult for me is that configuration issues aside...this setup has worked without issue for years now and something changed that wasn't explicitly done by me. It makes troubleshooting on my own difficult.

I also for my life can't figure out where it is picking up my laptop name from. It is actually picking up the name I have assigned in my windows partition (Dual Boot). But there isn't any way Linux can be talking to that partition right?

----------

## khayyam

 *Budoka wrote:*   

> I am a little confused. I did do this when initially setting my system up. Are you indicating that I can't or it isn't ideal to set my hostname to localhost?

 

Budoka ... it's a few weeks back now but as I remember your hosts file doesn't contain fields stating that 'localhost' (the hostname) is 'localhost' (the loopback). You could use 'localhost' but you're better setting it to a less confusing name, eg:

```
127.0.0.1 laptop.local laptop localhost
```

This will result in the following:

```
# busybox hostname -i

127.0.0.1

# busybox hostname -s

laptop

# busybox hostname -f

laptop.local

# busybox hostname -d

local
```

 *Budoka wrote:*   

> Part of what is difficult for me is that configuration issues aside...this setup has worked without issue for years now and something changed that wasn't explicitly done by me. It makes troubleshooting on my own difficult.

 

There are various ways you might get a hostname binary, sys-apps/net-tools, sys-apps/coreutils[hostname], or, as I do, via linking to busybox. I'm not sure what might have changed as I haven't updated openrc in a long time and so I'm not sure what /etc/init.d/hostname is doing these days. I'm additionally not sure about what NM does, or how this might have changed.

 *Budoka wrote:*   

> I also for my life can't figure out where it is picking up my laptop name from. It is actually picking up the name I have assigned in my windows partition (Dual Boot). But there isn't any way Linux can be talking to that partition right?

 

Perhaps you have it set in CONFIG_DEFAULT_HOSTNAME

best ... khay

----------

## Budoka

 *khayyam wrote:*   

>  *Budoka wrote:*   I am a little confused. I did do this when initially setting my system up. Are you indicating that I can't or it isn't ideal to set my hostname to localhost? 
> 
> Budoka ... it's a few weeks back now but as I remember your hosts file doesn't contain fields stating that 'localhost' (the hostname) is 'localhost' (the loopback). You could use 'localhost' but you're better setting it to a less confusing name, eg:
> 
> ```
> ...

 

Yes. I am sorry I dropped the ball on this for a bit. Had to put it on the back burner for a while.

I'll play with it some more based on the info you provided and will report back. Definitely a learning experience. LOL

Best

----------

## Budoka

 *khayyam wrote:*   

>  *Budoka wrote:*   I am a little confused. I did do this when initially setting my system up. Are you indicating that I can't or it isn't ideal to set my hostname to localhost? 
> 
> Budoka ... it's a few weeks back now but as I remember your hosts file doesn't contain fields stating that 'localhost' (the hostname) is 'localhost' (the loopback). You could use 'localhost' but you're better setting it to a less confusing name, eg:
> 
> ```
> ...

 

So I have been stepping through this to see if I can make any progress and I really am stuck. First, let me apologize if any of this really seems obvious to others...unfortunately, it just isn't to me.

So CONFIG_DEFAULT_HOSTNAME is null so it isn't coming from there.

I took your advice and set /etc/hosts to something a little more intuitive. After doing so checked with busybox the way you did and it returned exactly what one would expect.

```
127.0.0.1 TL_Samsung.local TL_Samsung localhost
```

```

$ busybox hostname -i

127.0.0.1

$ busybox hostname -s

TL_Samsung

$ busybox hostname -f

TL_Samsung.local

$ busybox hostname -d

local

```

But when I reboot...it reverts back to the "localhost" naming.

```
$ busybox hostname -i

hostname: localhost.localdomain: Host name lookup failure

$ busybox hostname -s

localhost

$ busybox hostname -f

hostname: localhost.localdomain: Host name lookup failure

$ busybox hostname -d

hostname: localhost.localdomain: Host name lookup failure
```

When I connect to my network via wifi then it changes and I am forced to login and out again to get anything to work.

So clearly localhost is being picked up from someplace other than /etc/hosts and the network manager is making a change somwhere but for my life, I can't figure out where!

On this wiki page,https://wiki.gentoo.org/wiki/NetworkManager#Configuration, I found this reference:

 *Quote:*   

> Hostname problems
> 
> The standard "keyfile" plugin does not forward the hostname in default configuration - to avoid having it changed upon network connection, add the following section to your NetworkManager.conf and enter your hostname accordingly:
> 
> FILE /etc/NetworkManager/NetworkManager.conf
> ...

 

So I defined hostname there as well and it did absolutely nothing. As best I can tell that config file isn't being read at all. I don't know if that is correct or incorrect but it didn't solve the problem defining it there.

I am stumped, frustrated, and a little out of my depth.

Is it possible that this is a networkmanager issue?

----------

## khayyam

Budoka ...

just to be sure:

You're also setting 'hostname=TL_Samsung' in /etc/conf.d/hostname?

You're using systemd?

best ... khay

----------

## Budoka

 *khayyam wrote:*   

> Budoka ...
> 
> just to be sure:
> 
> You're also setting 'hostname=TL_Samsung' in /etc/conf.d/hostname?
> ...

 

That was the missing piece! Thanks a lot khay. Now that it is fixed I will re-read the entire thread and try to understand what exactly happened.

----------

