Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
hostname is being changed by networkmanager (maybe?)*SOLVED*
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
Budoka
l33t
l33t


Joined: 03 Jun 2012
Posts: 667
Location: Tokyo, Japan

PostPosted: Tue Dec 27, 2016 11:18 pm    Post subject: hostname is being changed by networkmanager (maybe?)*SOLVED* Reply with quote

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:[url][https://forums.gentoo.org/viewtopic-t-1054136-highlight-.html/url]

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


Last edited by Budoka on Fri Jan 20, 2017 12:54 am; edited 1 time in total
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1360
Location: Montréal

PostPosted: Wed Dec 28, 2016 12:46 am    Post subject: Reply with quote

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

Code:
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.
_________________
Paul
Back to top
View user's profile Send private message
Budoka
l33t
l33t


Joined: 03 Jun 2012
Posts: 667
Location: Tokyo, Japan

PostPosted: Wed Dec 28, 2016 1:08 am    Post subject: Reply with quote

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

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


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
Code:
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
# local hosts that share this file.
#
# The format of lines in this file is:
#
# IP_ADDRESS canonical_hostname [aliases...]
#
#The fields can be separated by any number of spaces or tabs.
#
# In the presence of the domain name service or NIS, this file may not be
# consulted at all; see /etc/host.conf for the resolution order.
#

# IPv4 and IPv6 localhost aliases
127.0.0.1 localhost
::1 localhost

#
# Imaginary network.
#10.0.0.2 myname
#10.0.0.3 myfriend
#
# According to RFC 1918, you can use the following IP networks for private
# nets which will never be connected to the Internet:
#
# 10.0.0.0 - 10.255.255.255
# 172.16.0.0 - 172.31.255.255
# 192.168.0.0 - 192.168.255.255
#
# In case you want to be able to connect directly to the Internet (i.e. not
# behind a NAT, ADSL router, etc...), you need real official assigned
# numbers. Do not try to invent your own network numbers but instead get one
# from your network provider (if any) or from your regional registry (ARIN,
# APNIC, LACNIC, RIPE NCC, or AfriNIC.)
#


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


Joined: 16 Sep 2005
Posts: 1360
Location: Montréal

PostPosted: Wed Dec 28, 2016 1:52 am    Post subject: Reply with quote

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


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

PostPosted: Wed Dec 28, 2016 12:27 pm    Post subject: Reply with quote

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:

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

Code:
# cat /etc/hosts
127.0.0.1 myhostname localhost
::1 myhostname localhost

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

Code:
# 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.
_________________
Clevo W230SS: amd64 OpenRC elogind nvidia-drivers & xf86-video-intel.
Compal NBLB2: ~amd64 OpenRC elogind xf86-video-ati. Dual boot Win 7 Pro 64-bit.
KDE on both.

Fitzcarraldo's blog


Last edited by Fitzcarraldo on Sun Feb 19, 2017 11:43 pm; edited 2 times in total
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Wed Dec 28, 2016 4:28 pm    Post subject: Reply with quote

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

Code:
hostname="localhost"

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

best ... khay
Back to top
View user's profile Send private message
Budoka
l33t
l33t


Joined: 03 Jun 2012
Posts: 667
Location: Tokyo, Japan

PostPosted: Tue Jan 17, 2017 6:29 pm    Post subject: Reply with quote

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

Code:
hostname="localhost"

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

best ... khay


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?
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Tue Jan 17, 2017 7:17 pm    Post subject: Reply with quote

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:

/etc/hosts:
127.0.0.1 laptop.local laptop localhost

This will result in the following:

Code:
# 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
Back to top
View user's profile Send private message
Budoka
l33t
l33t


Joined: 03 Jun 2012
Posts: 667
Location: Tokyo, Japan

PostPosted: Tue Jan 17, 2017 9:24 pm    Post subject: Reply with quote

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:

/etc/hosts:
127.0.0.1 laptop.local laptop localhost

This will result in the following:

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


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


Joined: 03 Jun 2012
Posts: 667
Location: Tokyo, Japan

PostPosted: Wed Jan 18, 2017 6:27 pm    Post subject: Reply with quote

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:

/etc/hosts:
127.0.0.1 laptop.local laptop localhost

This will result in the following:

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


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.

Code:
127.0.0.1 TL_Samsung.local TL_Samsung localhost


Code:

$ 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.

Code:
$ 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
[keyfile]
hostname=your_hostname


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?
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Wed Jan 18, 2017 11:13 pm    Post subject: Reply with quote

Budoka ...

just to be sure:

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

best ... khay
Back to top
View user's profile Send private message
Budoka
l33t
l33t


Joined: 03 Jun 2012
Posts: 667
Location: Tokyo, Japan

PostPosted: Fri Jan 20, 2017 12:53 am    Post subject: Reply with quote

khayyam wrote:
Budoka ...

just to be sure:

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

best ... khay

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