[SOLVED] hostname changes based on network connection
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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.
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.
Last edited by BryanFRitt; 02-05-2018 at 02:49 AM.
Reason: deja-dup localhost changed to computer name to reflect what it says.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.