hostname keeps returning to linux if I set localhost.localdomain
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
hostname keeps returning to linux if I set localhost.localdomain
Hi
I formatted my laptop that was in Fedora (after 10 years on Fedora) I reinstalled with Mint 19. Everything is perfect, even better that 18 that gave me troubles with multiple monitors and other hardware issues.
I need help because since forever, my OS was named (I know, my mistake) as localhost.localdomain, and I have several cloud servers with ssh authentication disabled and I have access only through ssh keys.
I restored /etc/ssh/ and .ssh home directory but I need to set the hostname as localhost.localdomain to gain access to those servers. At the installation process, I didn't remembered and entered "randall" as hostname. After that, now, I change hostname:
/etc/hosts
/etc/hostname
hostname localhost.localdomain
sudo hostnamectl set-hostname localhost.localdomain
If I try to restart hostname it gives me this:
root@linux:/home/rrodriguez/kororaviejo# systemctl restart hostname
Failed to restart hostname.service: Unit hostname.service is masked.
the whole process is I guess with some protection policy that keeps getting back the laptop to
root@linux instead of root@localhost
If I check the hostname it will thel "linux"
If I repeat the process without reboot it will still show "root@linux" but the hostname will output "localhost.localdomain" but do not connect to my servers
If I cannot solve this I will have to return to Fedora and I am very happy with my new Mint 19
thanks
I formatted my laptop that was in Fedora (after 10 years on Fedora) I reinstalled with Mint 19. Everything is perfect, even better that 18 that gave me troubles with multiple monitors and other hardware issues.
I need help because since forever, my OS was named (I know, my mistake) as localhost.localdomain, and I have several cloud servers with ssh authentication disabled and I have access only through ssh keys.
I restored /etc/ssh/ and .ssh home directory but I need to set the hostname as localhost.localdomain to gain access to those servers. At the installation process, I didn't remembered and entered "randall" as hostname. After that, now, I change hostname:
/etc/hosts
/etc/hostname
hostname localhost.localdomain
sudo hostnamectl set-hostname localhost.localdomain
If I try to restart hostname it gives me this:
root@linux:/home/rrodriguez/kororaviejo# systemctl restart hostname
Failed to restart hostname.service: Unit hostname.service is masked.
the whole process is I guess with some protection policy that keeps getting back the laptop to
root@linux instead of root@localhost
If I check the hostname it will thel "linux"
If I repeat the process without reboot it will still show "root@linux" but the hostname will output "localhost.localdomain" but do not connect to my servers
If I cannot solve this I will have to return to Fedora and I am very happy with my new Mint 19
thanks
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: hostname keeps returning to linux if I set localhost.localdomain
These two are all that you need and you don't even need to sudo it (strangely, tbh), and strictly speaking you don't even need to change the second one, although it's better to change it, too:randallrodriguezw wrote: ⤴Wed Jul 25, 2018 1:14 pmAfter that, now, I change hostname:
/etc/hosts
/etc/hostname
hostname localhost.localdomain
sudo hostnamectl set-hostname localhost.localdomain
If I try to restart hostname it gives me this:
Code: Select all
hostnamectl set-hostname localhost.localdomain
/etc/hosts
Last edited by gm10 on Wed Jul 25, 2018 1:52 pm, edited 1 time in total.
Re: hostname keeps returning to linux if I set localhost.localdomain
hello gm10, and thanks for your post
every way I change the hostname it shows "root@linux". If I reboot the computer that asks for the hostname it says "linux". If I changed back to localhost.localdomain and look for /etc/hosts and /etc/hostname the contents is correctly localhost.localdomain but it only temporarily changes to "localhost.localdomain" if I set it up with "hostname localhost.localdomain" but it is getting back to "linux" after reboot.
Anyway, with "linux" or temporarily changed with hostname command, I do not get access to my servers with ssh keys
every way I change the hostname it shows "root@linux". If I reboot the computer that asks for the hostname it says "linux". If I changed back to localhost.localdomain and look for /etc/hosts and /etc/hostname the contents is correctly localhost.localdomain but it only temporarily changes to "localhost.localdomain" if I set it up with "hostname localhost.localdomain" but it is getting back to "linux" after reboot.
Anyway, with "linux" or temporarily changed with hostname command, I do not get access to my servers with ssh keys
Re: hostname keeps returning to linux if I set localhost.localdomain
While I seem to be able to set it successfully with just hostnamectl, I'd guess the problem is that localhost.localdomain isn't technically a correct hostname. localhost is the hostname, localdomain is the domain.
So try setting the hostname to just localhost via hostnamectl and then set up the local domain where you're supposed to, in /etc/hosts:
So try setting the hostname to just localhost via hostnamectl and then set up the local domain where you're supposed to, in /etc/hosts:
127.0.0.1 localhost.localdomain localhost
(that should be the only entry defining localhost). If you did it correctly, hostname --fqdn
should then output localhost.localdomain.Re: hostname keeps returning to linux if I set localhost.localdomain
Permission is granted through Polkit to "admin" users, on our systems defined to be, c.f. /etc/polkit-1/localauthority.conf.d/, unix-user:0 (root), unix-group:sudo (administrative users on Mint) and unix-group:admin.
Re: hostname keeps returning to linux if I set localhost.localdomain
Thanks. What I meant was I find it strange that it's set up like that, the hostname isn't something you trivially change, it makes changes to system files, it should really ask for you a password to authorize this change. It goes against the usual *nix security paradigm to set it up otherwise IMHO.
Re: hostname keeps returning to linux if I set localhost.localdomain
I'll wait a bit to agree nor disagree until poster has had his issue dealt with. In which sense...
I just tested this and while
It's this transient, current hostname that is shown in the prompt and poster finding it getting reset to "linux" means that either his DHCP server (i.e., home router) provides the hostname "linux" or "linux.something" to the system or that he has a line e.g.
Given that poster mentioned to have named the system "randall" rather than "linux" during install, I expect the former. If so and if -- and it's somewhat of an if indeed -- the router allows it, poster could change the hostname from "linux" to "localhost.localdomain" in the router. If the router is not involved after all it's a simple matter of changing /etc/hosts to have
Yes, that's a wrong solution seeing as how nothing other than 127.0.0.1, the loopback interface, should ever be named localhost or even localhost.localdomain but seeing as how poster seems to for now need this to get some historical fault continued, oh well; the proper solution is to change the hostname to something sensible instead.
So, to summarise:
1. Check your router to see if it's handing out the "linux" or "linux.something" hostname as part of the DHCP protocol; try to change it there if so.
2. If not, simply add
2 has been verified to work here:
Don't let the fact that only "localhost" is displayed in the prompt confuse matters: that's just how the prompt is setup on Mint:
Change all instances of \h to \H in the various PS1= lines in ~/.bashrc if you insist on making that permanent.
I just tested this and while
hostnamectl set-hostname localhost.localdomain
is accepted without issue and correctly sets the (static) hostname to localhost.localdomain, including over reboot, it's then NetworkManager that upon starting a connection decides semi-correctly that localhost.localdomain nor, by the way, localhost is an acceptable hostname for a connected system and sets the transient hostname to either the hostname it got from DHCP, or if none, the reverse-resolved hostname for the connection IP. As far as I've been able to see no current method exists to tell Networkmanager to just leave well enough alone.It's this transient, current hostname that is shown in the prompt and poster finding it getting reset to "linux" means that either his DHCP server (i.e., home router) provides the hostname "linux" or "linux.something" to the system or that he has a line e.g.
192.168.1.123 linux ...
in his /etc/hosts file, with of course 192.168.1.123 replaced by whichever IP the at boot automatically started interface gets. Given that poster mentioned to have named the system "randall" rather than "linux" during install, I expect the former. If so and if -- and it's somewhat of an if indeed -- the router allows it, poster could change the hostname from "linux" to "localhost.localdomain" in the router. If the router is not involved after all it's a simple matter of changing /etc/hosts to have
192.168.1.123 localhost.localdomain localhost ...
and comment out any other entries for localhost (i.e., 127.0.0.1) that may be present.Yes, that's a wrong solution seeing as how nothing other than 127.0.0.1, the loopback interface, should ever be named localhost or even localhost.localdomain but seeing as how poster seems to for now need this to get some historical fault continued, oh well; the proper solution is to change the hostname to something sensible instead.
So, to summarise:
1. Check your router to see if it's handing out the "linux" or "linux.something" hostname as part of the DHCP protocol; try to change it there if so.
2. If not, simply add
192.168.1.123 localhost.localdomain localhost ...
to /etc/hosts and comment out any other entries for localhost.localdomain and localhost. Replace 192.168.1.123 with the IP that the/a automatically at boot by NetworkManager started connection gets.2 has been verified to work here:
Code: Select all
rene@localhost ~ $ hostname
localhost.localdomain
rene@localhost ~ $ hostname -f
localhost.localdomain
rene@localhost ~ $ hostnamectl --static
localhost.localdomain
rene@localhost ~ $ hostnamectl --transient
localhost.localdomain
rene@localhost ~ $ hostnamectl --pretty
rene@localhost ~ $
Code: Select all
rene@localhost ~ $ PS1=${PS1//\h/\H}
rene@localhost.localdomain ~ $
Re: hostname keeps returning to linux if I set localhost.localdomain
Noticing upon rereading that a slightly different alternative scenario is more likely; poster indeed having a
I.e., if you don't yet have your router setup for "static IP via DHCP" by reserving certain IP addresses for certain MAC addresses in the router configuration you will want to so now to guarantee that, e.g., 192.168.1.123 is always provided to you; get the MAC address of your interface from the link/ether part for your interface in the output of
192.168.1.123 linux ...
line in his /etc/hosts but this being a left-over from back when 192.168.1.123 in fact was the machine "linux"; the IPs having changed since then.I.e., if you don't yet have your router setup for "static IP via DHCP" by reserving certain IP addresses for certain MAC addresses in the router configuration you will want to so now to guarantee that, e.g., 192.168.1.123 is always provided to you; get the MAC address of your interface from the link/ether part for your interface in the output of
ip addr
. You can then do the "2" thing without issue...Re: hostname keeps returning to linux if I set localhost.localdomain
A hostname different from yours for an IP different from yours should not have any impact on the issue at hand though, or what am I not considering? The "linux" hostname displayed in the terminal isn't pulled from the hosts file, either.rene wrote: ⤴Sat Jul 28, 2018 11:04 am Noticing upon rereading that a slightly different alternative scenario is more likely; poster indeed having a192.168.1.123 linux ...
line in his /etc/hosts but this being a left-over from back when 192.168.1.123 in fact was the machine "linux"; the IPs having changed since then.
Otherwise I believe we are in agreement with our suggestion and you raised some good additional points.
Re: hostname keeps returning to linux if I set localhost.localdomain
It is/can be in this case, as explained through the intermediate step of NetworkManager setting the (transient) hostname upon considering localhost.localdomain invalid when bringing up a connection, to either a DHCP-received hostname if any, or the reverse-resolved one for the IP it just brought up otherwise, i.e., gethostbyaddr(), i.e., from /etc/hosts if the address is specified there.
The difference between your suggestion above and my suggestion 2 is relevant; while you suggest 127.0.0.1 for localhost.localdomain and localhost -- and while that's obviously the only correct thing to do -- poster is seemingly in a situation where he for now needs his non-loopback IP linked to the localhost.localdomain name. With NetworkManager being a pain in the butt this needs doing through either router if applicable and/or /etc/hosts otherwise.
[edited]
You can verify this being a NetworkManager thing by
hostnamectl set-hostname localhost.localdomain
, disable automatic connections in NetworkManager (the network icon in your systray), reboot and see the localhost.localdomain hostname to have stuck. By then starting the network connection manually and seeing the transient hostname reverting back to the DHCP/hosts name.[/edited]
Anyways, the idea was to postpone talking among our ourselves until poster's issue was dealt with, so let's try and wait for him to show up again...