LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2018, 10:20 AM   #1
BryanFRitt
Member
 
Registered: May 2004
Distribution: Debian
Posts: 39

Rep: Reputation: 1
hostname changes based on network connection


[Debian 9.x Stable Stretch, KDE]

I tried to change or keep my 'hostname' to 'PC', but it doesn't stick.
Code:
echo PC | sudo tee /etc/hostname
sudo hostname PC
sudo hostnamectl set-hostname PC
But it changes when I switch how I connect to the network. (Wi-Fi, Ethernet, ...)

How can I keep the hostname the same no matter what the network connection? or should I not do this?

inside of my /etc/hosts file
Quote:
127.0.0.1 localhost

::1 ip6-localhost ip6-loopback
::1 localhost6.localdomain6 localhost6
::1 localhost ip6-localhost ip6-loopback
::1 localhost
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

127.0.0.1 PC

Last edited by BryanFRitt; 02-04-2018 at 11:00 AM. Reason: Added /etc/hosts
 
Old 02-04-2018, 03:29 PM   #2
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Check how the DHCP client is configured. (For example, the 'send host-name' option in dhclient.conf)
 
Old 02-04-2018, 04:05 PM   #3
BryanFRitt
Member
 
Registered: May 2004
Distribution: Debian
Posts: 39

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by ferrari View Post
Check how the DHCP client is configured. (For example, the 'send host-name' option in dhclient.conf)
I found a /etc/dhcp/dhclient.conf file. It had "send host-name = gethostname();" in it.

Quote:
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
The rest was commented out.

What does this statement do?, and how to fix things?

Should I change it to something like "send host-name = 'PC';"?
Just tried that and it didn't fix anything.

Last edited by BryanFRitt; 02-04-2018 at 04:09 PM.
 
Old 02-04-2018, 04:18 PM   #4
BryanFRitt
Member
 
Registered: May 2004
Distribution: Debian
Posts: 39

Original Poster
Rep: Reputation: 1
I can change the hostname to 'PC' temporarily with those commands, but after 2nd reboot with the network device connected, the hostname isn't kept, and the hostname changes whenever I disconnect one network connection and activate another one.
 
Old 02-04-2018, 04:40 PM   #5
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Are you using NetworkManager to manage your connections?

First you need to establish which DHCP client is in use.

The following command might help with that
Code:
ps -A|grep dh
 
Old 02-04-2018, 04:51 PM   #6
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Quote:
I found a /etc/dhcp/dhclient.conf file. It had "send host-name = gethostname();" in it.

Quote:
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
The rest was commented out.

What does this statement do?, and how to fix things?
If dhclient really is use, that should be sufficient, and it can also be hard set as you mentioned. However, you need to answer the question about whether you're using NetworkManager.
 
Old 02-04-2018, 05:00 PM   #7
BryanFRitt
Member
 
Registered: May 2004
Distribution: Debian
Posts: 39

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by ferrari View Post
Are you using NetworkManager to manage your connections?

First you need to establish which DHCP client is in use.

The following command might help with that
Code:
ps -A|grep dh
results in
Quote:
5139 ? 00:00:00 dhclient
 
Old 02-04-2018, 05:20 PM   #8
BryanFRitt
Member
 
Registered: May 2004
Distribution: Debian
Posts: 39

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by ferrari View Post
If dhclient really is use, that should be sufficient, and it can also be hard set as you mentioned. However, you need to answer the question about whether you're using NetworkManager.
I tried the "hard set" method, and it didn't work. Still goes by network device name.

If I use those `sudo hostname PC` commands it'll keep the hostname on the first reboot, but on second, etc... the hostname will go by the network device name.(not sure what to call it.) I can tell this by the KDE login screen's message "Welcome to ...". [UPDATE: on this screen I can choose restart X server, and the hostname shown will change to one based on network device]

It is possible I may have (in/un)installed/changed something that effects this when dealing with NVidia video card drivers, and/or OS recovery. ?Don't know?

Last edited by BryanFRitt; 02-04-2018 at 05:56 PM.
 
Old 02-04-2018, 05:21 PM   #9
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Ok, and are you using NetworkManager or a connection defined in /etc/network/interfaces?
 
Old 02-04-2018, 05:41 PM   #10
BryanFRitt
Member
 
Registered: May 2004
Distribution: Debian
Posts: 39

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by ferrari View Post
Ok, and are you using NetworkManager or a connection defined in /etc/network/interfaces?
I haven't explicitly set any network manager that I know of.
Code:
cat /etc/network/interfaces | egrep -v '#|^$'
Quote:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
dns-nameservers 208.67.220.123 208.67.222.123
The dns-nameservers are for OpenDNS FamilyShield
Code:
ls -aR /etc/network/interfaces*
Quote:
/etc/network/interfaces

/etc/network/interfaces.d:
. ..

Last edited by BryanFRitt; 02-04-2018 at 05:50 PM.
 
Old 02-04-2018, 05:50 PM   #11
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Well, to be connected to the internet you're likely to be using one or the other. Based on the the last post, I assume NM is running
Code:
ps -A|grep -i net
https://manpages.debian.org/testing/...conf.5.en.html
Quote:
hostname-mode
Set the management mode of the hostname. This parameter will affect only the transient hostname. If a valid static hostname is set, NetworkManager will skip the update of the hostname despite the value of this option. An hostname empty or equal to 'localhost', 'localhost6', 'localhost.localdomain' or 'localhost6.localdomain' is considered invalid.

default: NetworkManager will update the hostname with the one provided via DHCP on the main connection (the one with a default route). If not present, the hostname will be updated to the last one set outside NetworkManager. If it is not valid, NetworkManager will try to recover the hostname from the reverse lookup of the IP address of the main connection. If this fails too, the hostname will be set to 'localhost.localdomain'.

dhcp: NetworkManager will update the transient hostname only with information coming from DHCP. No fallback nor reverse lookup will be performed, but when the dhcp connection providing the hostname is deactivated, the hostname is reset to the last hostname set outside NetworkManager or 'localhost' if none valid is there.

none: NetworkManager will not manage the transient hostname and will never set it.
 
Old 02-04-2018, 06:26 PM   #12
BryanFRitt
Member
 
Registered: May 2004
Distribution: Debian
Posts: 39

Original Poster
Rep: Reputation: 1
Code:
ps -A|grep -i net
Quote:
56 ? 00:00:00 netns
964 ? 00:00:00 inetd
1012 ? 00:00:06 NetworkManager
 
Old 02-04-2018, 07:03 PM   #13
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Ok, that confirms NetworkManager.

Hmmm...the Debian Stretch NM reference suggests NM honours the name set in /etc/hostname
https://manpages.debian.org/stretch/...conf.5.en.html

By default dhclient is used by NetworkManager, so that is where the hostname is pushed from.
Quote:
dhcp
This key sets up what DHCP client NetworkManager will use. Allowed values are dhclient, dhcpcd, and internal. The dhclient and dhcpcd options require the indicated clients to be installed. The internal option uses a built-in DHCP client which is not currently as featureful as the external clients.

If this key is missing, it defaults to dhclient. It the chosen plugin is not available, clients are looked for in this order: dhclient, dhcpcd, internal.
 
Old 02-04-2018, 07:18 PM   #14
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Returning to the dhclient.conf config you posted in post #3
Code:
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
Remove the 'host-name' entry from the request, and check behaviour after restarting NetworkManager or perhaps reboot.

This might be useful to you...
https://support.cumulusnetworks.com/...stname-Option-
 
Old 02-04-2018, 08:04 PM   #15
BryanFRitt
Member
 
Registered: May 2004
Distribution: Debian
Posts: 39

Original Poster
Rep: Reputation: 1
Thought this fixed it for a while, hostname is staying 'PC' and not changing based on network interface, but...
Now deja-dup is saying computer name is localhost instead of 'PC' or the network interface name.

Do I need to put "127.0.0.1 PC" before "127.0.0.1 localhost" in /etc/hosts ? or change another file?

What I did (not sure why I looked this up...)
Code:
apt-file search /etc/init.d/hostname.sh
Quote:
initscripts: /etc/init.d/hostname.sh
Code:
sudo apt-get purge initscripts
Code:
sudo hostname PC
sudo hostnamectl set-hostname PC
[UPDATE]forgot to say I reinstalled initscripts back later[/UPDATE]
---
Haven't tried this yet
Quote:
Remove the 'host-name' entry from the request, and check behaviour after restarting NetworkManager or perhaps reboot.
Attached Thumbnails
Click image for larger version

Name:	Deja-Dup_Computer_Name_Changed_Back_Up.png
Views:	31
Size:	41.0 KB
ID:	26915  

Last edited by BryanFRitt; 02-05-2018 at 02:49 AM. Reason: deja-dup localhost changed to computer name to reflect what it says.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to filter condition based on full hostname? Winanjaya Linux - Security 1 05-20-2010 01:17 AM
simple forwarding based on hostname/port Kallin Linux - Server 3 09-09-2008 02:47 PM
changing hostname with out fouling up network connection? bezdomny Linux - Networking 10 07-23-2008 08:20 AM
MAC Address based hostname hogg85 Linux - Networking 2 06-13-2005 01:51 PM
Connection to external hostname from outside ok but rejected from inside network Dalvinio Linux - Networking 0 03-11-2005 07:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration