Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Unexpected change of the hostname
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
doskanoness
n00b
n00b


Joined: 06 Oct 2021
Posts: 45

PostPosted: Sat Nov 06, 2021 5:26 pm    Post subject: Unexpected change of the hostname Reply with quote

I have a problem with an unexpected change of the hostname. When I connect through LAN or by Wi-Fi to my home network, hostname is changed from gentoo to new-host-3. I use NetworkManager to connect to the network.

/etc/hosts:
Code:
# /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       gentoo.spacev7.org gentoo localhost
::1             gentoo.spacev7.org gentoo 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.)
#


/etc/conf.d/hostname:
Code:
# Hostname fallback if /etc/hostname does not exist
hostname="localhost"


/etc/hostname:
Code:
gentoo


Router console:
https://i.imgur.com/opVjVij.png
Back to top
View user's profile Send private message
Mistwolf
Apprentice
Apprentice


Joined: 07 Mar 2007
Posts: 189
Location: Edmonton, AB

PostPosted: Sat Nov 06, 2021 5:36 pm    Post subject: Reply with quote

make sure hostname-mode is set to none in networkmanager.conf
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3879

PostPosted: Sat Nov 06, 2021 5:40 pm    Post subject: Reply with quote

Is this a systemd installation?
If yes plz use
Code:

hostnamectl set-hostname gentoo

_________________
:)


Last edited by alamahant on Sat Nov 06, 2021 5:50 pm; edited 2 times in total
Back to top
View user's profile Send private message
doskanoness
n00b
n00b


Joined: 06 Oct 2021
Posts: 45

PostPosted: Sat Nov 06, 2021 5:49 pm    Post subject: Reply with quote

Quote:

Is this a systemd installation?

No, OpenRC.
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3879

PostPosted: Sat Nov 06, 2021 5:50 pm    Post subject: Reply with quote

If it is a NM issue then use
Code:

nmcli general hostname gentoo

_________________
:)
Back to top
View user's profile Send private message
doskanoness
n00b
n00b


Joined: 06 Oct 2021
Posts: 45

PostPosted: Sat Nov 06, 2021 6:03 pm    Post subject: Reply with quote

Mistwolf wrote:
make sure hostname-mode is set to none in networkmanager.conf

Thank you very much. Problem is solved.
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


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

PostPosted: Sat Nov 06, 2021 11:36 pm    Post subject: Reply with quote

Which DHCP client have you specified in the USE flags for NetworkManager? The preferred one by the NetworkManager developers is dhclient.

I specify the laptop’s hostname in /etc/hosts, /etc/conf.d/hostname, /etc/hostname and /etc/dhcp/dhclient.conf:

Code:
# grep -v "^#\|^$" /etc/hosts
127.0.0.1       clevow230ss     localhost
::1             clevow230ss     localhost


Code:
# cat /etc/conf.d/hostname
# Set to the hostname of this machine
hostname="clevow230ss"


Code:
# cat /etc/hostname
clevow230ss


Code:
# grep -v "^#\|^$" /etc/dhcp/dhclient.conf
send host-name "clevow230ss";
supersede host-name "clevow230ss";


The purpose of the ‘supersede‘ statement in dhclient.conf is explained in man dhclient.conf(5):

Quote:

supersede [ option declaration ] ;

If for some option the client should always use a locally-configured value or values rather than whatever is supplied by the server, these values can be defined in the supersede statement.


In other words, I do not want the hostname to be specified by a dhcp server (as this has caused problems for me in the past when connected to some networks).

I edited the configuration file /etc/NetworkManager/NetworkManager.conf to contain the following:
Code:
[main]
plugins=keyfile
rc-manager=none
dhcp=dhclient
no-auto-default=*
 
[keyfile]
hostname=clevow230ss

In earlier days it was necessary to specify the hostname in /etc/NetworkManager/NetworkManager.conf but that is no longer required. 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." I just left it in the file because it does no harm.
_________________
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