Hostname inexplicably altered

Ok, no longer “inexplicable” but I thought I’d share this as it had me worried for a bit (some people will think its obvious but not everyone is a veteran *nix expert) .

My terminal prompt suddenly changed from bob@localhost to bob@support on one occassion and bob@mail on another and my logs were showing mail.google.com in the host field. At first I thought I’d been hacked but there were no other signs…

I was looking at the logs on another issue when I saw the mail.yahoo.com and then found changes being made by NetworkManager… which I had restarted. Turns out NetworkManager was changing it.

Anyway, check out hostname-mode in (man) NetworkManager.conf - one solution is to set it =none.
And thanks to Thomas Haller over at Red Hat for the solution there.

1 Like

This seems like an extremely specific issue to your environment. First of all, from this documentation it seems that hostname-mode only comes into play if you haven’t set a hostname (localhost is considered “unset”, with some variations), so if you had given the machine a hostname this issue would not present itself.

Secondly, if hostname-mode actually does come into play, here’s what it should do according to the documentation:

NetworkManager will update the hostname with the one provided via DHCP or reverse DNS lookup of the IP address on the connection with the default route

So does this mean your DHCP server provides multiple hostnames for your system (support, mail etc.) – or that your DNS server has PTR records that points DNS queries of “mail” or “support” to the IP of that server?

If you ask me, the main issue from the start here is that the system does not have a set hostname. This is extremely uncommon for any system that would also have PTR records in a DNS server.

The “solution” offered really only disables the functionality in NetworkManager but I would argue in the vast majority of cases, this feature is probably a good thing.

Yes, there is the question of where those server names came from / how they were arrived at - I didn’t set them - at least not knowingly. I’m assuming the “mail” seen in my prompt was related to the “mail.google.com” seen in my logs… again it’s currently a mystery to me. Alas, 'tis one of a never ending list of issues to resolve as I venture ever deeper down the rabbit hole that is modern Linux.

The documentation is impenetrable on initial reads to someone who isn’t a network engineer: the IP address on the connection with the default route - what does that mean exactly ? - but I’ll obviously have to figure it out eventually when I have time/get around to it - the system I’m using is a “first pass” on the way (hopefully) to a reliable and sustainable system I can use to do some actual work.

The main issue is that the system applies a defacto default hostname but will alter it later based on criteria the end user cannot possibly be aware of unless they have studied the relevant component to a level that goes way beyond default usage. If someone thinks an end user should have to set a default hostname then that in itself is an issue;

Software is supposed to make the end user’s life easier and more productive - not require they continually delve into dry, often poorly wriiten technical documentation at every turn. It is a developer’s job to make a system as simple and intuitive to use and as robust as possible insofar as circumstances allow. The more effort I have to put into using a piece of software the less point there was in someone writing it.

I am months into trying to get a system that is as usable and acceptable as WIndows 7 was. The only reason I am persevering is that Windows 10+ has gone way beyond what is acceptable: “Pro” installs Disney+ by default (FFS!) and it would take me considerable effort just to remove all the consumer bloat installed by default and you can no longer get away from the invasive $h1t* arising from Microsoft’s insistence on trying to be a google/facebook style surveillance machine and of course, finally, you have no control over it - they actively work to reverse your changes and stop you making them again. Though of course I will be at the mercy of RH’s product steering team now instead.

This ends the Rant for today.

1 Like

As far as I can tell, the software is behaving exactly as described in the documentation.

The main issue is that the system applies a defacto default hostname but will alter it later

The issue will only occur in a situation where hostname is missing, i.e. you didn’t set one and it therefore defaults to “localhost”. This means that the issue can be avoided by setting a hostname, which is almost always done, even on desktop installations.

The documentation is impenetrable on initial reads to someone who isn’t a network engineer

In layman’s terms it’s saying that “if a DHCP or DNS server tells us that you have a specific hostname, we will honor that and change the hostname”. Which makes a lot of sense, and is probably what you want as the default behavior in most environments.

Note, again, that this only happens if you have not set a hostname yourself.

Also note that what’s commonly called Enterprise Linux (i.e. Red Hat, CentOS and now Rocky Linux) is mainly just that, an enterprise distribution of Linux for production systems. This means that stability and reliability is prioritized over new features, which is often a trade-off you want in production environments, not on a desktop that may need to support all kinds of peripherals or newer versions of software.

You can absolutely use Rocky as a regular desktop OS but it’s not primarily what it’s designed for, so if you are looking for something to replace Windows (which it sounds like) and you are not comfortable with administrating a Linux system I suggest you try a distribution that is more primarily focused on desktop users, for example Ubuntu or one of its derivatives.

In summary, the situation is as follows:

  • Your system lacks a hostname, it was not set
  • A DHCP or DNS server informs the operating system that you do have a hostname
  • The operating system accepts this and changes the hostname from “unset” to whatever the server informed it of.

If you ruminate over this for a minute, I think you can see that it makes a lot of sense in the 99,9% of cases that are not exactly like yours, i.e. when Rocky is being used as a server. If it does not make sense to you, perhaps consider that you are, as you say, “not a network engineer”, and that maybe it shouldn’t have to to accept that it’s probably the default for a reason.

1 Like

The default route is the route that is used when none of the more explicit routes matches.
In “normal setup” machine has one NIC, one IP address, one link-local subnet, and everything else uses the default route. The *gateway".

Even when machine is member of multiple (link-local) subnets, there is only one default route. (Although, NetworkManager can set multiple default routes, but there is precendence; only one is actually used.)

Policy routing can have “multiple defaults”, but that is for traffic that matches policy criteria; there is still only one default “default route”.

The default route directs traffic to gateway that is an another member of some link-local subnet. The machine has IP address that it uses as source in traffic that it sends to that subnet.

A NIC, a NetworkManager “connection”, can have more than one IP address. One of them might be treated as “primary”. That might be the “the IP address on the connection with the default route”. (Hey, we haven’t even mentioned IPv4 and IPv6 yet – a lot of “IP discussion” tends to be implicitly about IPv4.)

Your machine is not the mail.google.com, I presume. Therefore, name mail should not be due to that.
What do you get with hostnamectl?

[root@localhost bob]# hostnamectl
   Static hostname: localhost.localdomain
         Icon name: computer-desktop
           Chassis: desktop
        Machine ID: 1d6107f5cb03415d89932c93d325b366
           Boot ID: 5bfd2475d8db494c9794fa010a2927ed
  Operating System: Rocky Linux 8.4 (Green Obsidian)
       CPE OS Name: cpe:/o:rocky:rocky:8.4:GA
            Kernel: Linux 4.18.0-305.25.1.el8_4.x86_64
      Architecture: x86-64

Appreciate the response. This is not a priority for me at the moment / I’ll get to it eventually.

Ok, I think I see what you are saying: 99.9% of use cases depend on the hostname defaulting to a DHCP/DNS server provided hostname where it finds one and only in rare cases might you want to override that so the hostname should not be set by default.

I have not set any hostnames to “mail”. The behaviour I experienced was, to me - an end user, after a standard install, unexpected. Someone moving to Linux - and RL/RHEL provide a “Workstation” install - cannot be expected to know that the “default” as it initially appears in your prompts etc is not the “default”. (Where “mail” came from is still tbd)

Ubuntu is not an alternative to RL - selinux is a significant difference (aside from other concerns) and no, I don’t want to get into installing selinux on Ubuntu.

Obviously, in light of the above, I accept what you say about setting the hostname and I was wrong to say

Like you, I came to RockyLinux to flee the Seattle-based Evil Empire. While I’m not a Linux expert by any means, I’m a very senior developer and I’ve been using Linux servers in one form or another since the early 1980s (if you’ll allow me group Linux and Unix together).

The story that I tell myself that helps me feel better about Linux arcana like that mentioned here is that in RockyLinux (I currently run v8.5 rather than the v8.4 you report) I spend less time on this than I was spending doing even more frustrating tasks in the Windows world. At least in Linux such things are usually either resolvable or have a work-around, and I am aware of no entity that is as dedicated to stealing my time as that certain Seattle-based company that I won’t name.

My experience for some years now has been that I rely on various web-based sources to resolve every non-trivial issue that comes up – especially after any Windows Update since early 2020. I find that those sources are typically easier to find and more reliable for Linux in general and RockyLinux in particular than their counterparts for Windows.

While not perfect, I therefore remain happy that I’ve made the transition to RockyLinux.

I’ve landed on KDE as my desktop. It’s not great, but it gets in my way less than Gnome.

I chose RockyLinux because I’ve always felt that CentOS struck the best balance between features and robustness. After Redhat/IBM killed CentOS, Rocky Linux was the obvious replacement for CentOS 7.

Here, for comparison, is what I get from hostnamectl on my local machine:

[root@localhost ~]# hostnamectl 
   Static hostname: localhost.localdomain
         Icon name: computer-desktop
           Chassis: desktop
        Machine ID: 8c46f0db9ab242eea5f3c0f27b348cff
           Boot ID: 21890bbab52442a587ec2b41a3e7e272
  Operating System: Rocky Linux 8.5 (Green Obsidian)
       CPE OS Name: cpe:/o:rocky:rocky:8:GA
            Kernel: Linux 4.18.0-348.12.2.el8_5.x86_64
      Architecture: x86-64

My own way of addressing the thread-starter is that I manually edit /etc/hosttname. I go to some lengths to ensure that it contains a real, valid, and current domain name. Here is the response from hostnamectl on one of several AWS EC2 RockyLinux servers that I manage:

[root@byron ~]# hostnamectl
   Static hostname: byron.zeetix.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ee3563997878469ebfcc3f721aec3c66
           Boot ID: 2d56f6f1b418464e9937ec9e72cd5c9e
    Virtualization: kvm
  Operating System: Rocky Linux 8.5 (Green Obsidian)
       CPE OS Name: cpe:/o:rocky:rocky:8:GA
            Kernel: Linux 4.18.0-348.12.2.el8_5.x86_64
      Architecture: x86-64

Finally, let me say “welcome” from another RockyLinux community member.

1 Like

Hi @bobar

When your hostname changed, try to execute
hostname --fqdn and hostname -A
this command tell you about Fully Qualified Domain Name [ FQDN ].
This will at least clear your doubt that your getting mail as your hostname from mail.google.com.

I also think it is related to DNS.

You can also try to stop NetworkManager by using command:

systemctl stop NetworkManager
[You will be still connected with your machine over network but it will stop NetworkManager task (basically Automatically managing network services), so only perform under your observation ]
after that observe your machine behavior and problem existence.

Hope it will throw some light in this matter and help full for you.

6.2. Configuring Host Names Using Text User Interface, nmtui Red Hat Enterprise Linux 7 | Red Hat Customer Portal writes:

In Red Hat Enterprise Linux, NetworkManager uses the systemd-hostnamed service to read and write the static host name, which is stored in the /etc/hostname file. Due to this, manual modifications done to the /etc/hostname file are no longer picked up automatically by NetworkManager ; you should change the system host name through the hostnamectl utility.

An example, where machine gets config from DHCP via NetworkManager, including the hostname (DHCP and DNS are consistent about names):

$ ansible snafu -a 'cat /etc/hostname'
snafu | CHANGED | rc=0 >>
localhost.localdomain
$ ansible snafu -a hostnamectl
snafu | CHANGED | rc=0 >>
   Static hostname: localhost.localdomain
Transient hostname: snafu.mydomain.example
         Icon name: computer-server
           Chassis: server
...

Names can be used both ways with DHCP: a client can offer a name and server gives address for it, or the server gives both name and address to the client. Furthermore, DHCP server can update DNS server, for example to provide name-address when it allocates address from a pool. (The latter is trivial in dnsmasq that acts as both DHCP and DNS server.)

Heh. Indeed, I think I knew this – I just haven’t done it yet.

I appreciate the concise guidance, I’ll apply it as soon as I get a chance.

When you run the GUI Rocky installer, and get to the Network screen, I’d expect the hostname to be set at that point, before it’s even booted. This is assuming a simple workstation setup.

This is the screen as you find it. Details of how hostname is used can be found under the Help button but unless you’ve got ur Network Admin Hat on… or at least have such a hat lying around somewhere, you are likely to take what’s on the screen as “this is now the hostname for this device, period.” and move on.

I’m not knocking it - I accept that there are at least 2 completely different perspectives when it comes to looking at RL - a user who manages their own system and a network admin who manages multiple systems and who would want the same set of rules etc to apply to assigning hostnames to workstations as apply to servers.

Maybe a note “This may be overridden at runtime - see help for more info” but to to be fair, by the time it became an “issue” most non admin types will probably have forgotten about it - I had to check to see if setting it was even a part of the install.

Thanks for that @shalom. I’ll give it a try if/when I try to replicate the issue.

@SommervilleTom,

I’d echo your sentiments. It is impressive that RL/RHEL works as well and to the extent that it does and provides all the functionality it does - ditto for KDE but it is easy to lose sight of that at times.

In for the long haul - there’s no alternative.

Like others I Welcome you to the world of Linux. It seems you are trying to escape the clutches of “The Evil Empire”. I escaped circa 1999-2000. Prior to that i was a M$ DOS junky. If you are coming from the Land of Windows you may have discovered a nifty utility called Norton Commander, which is a file browsing utility. Well there a Linux equivalent called Midnight Commander that uses the EXACT same hot keys etc.as Norton Commander. If you have not already got it installed, to install it type dnf install mc.

To set the hostname is a trivial process.

  1. type su

  2. Enter your secret sauce root password

  3. type mc (this starts Midnight Commander)

  4. now browse over to /etc and scroll down until you find a file called hostname

  5. Hit F4 (This will open the file called /etc/hostname .( If you ONLY want to see the contents of /etc/hostname hit F3) More likely than not this file will be EMPTY. The DEFAULT is something called localhost.localdomain. You need to supply both a local host name and a local domain name.

  6. Give your machine a NAME. In my case ALL my machines are named after members of the CAT Family. The current machine I’m on is leopard, my new workstation is ocelot, and so on, or get creative and and give it a very unique name if you choose.

  7. Now you need to come up with a local domain name. Most people stick with their ISP’s name, or it might be something esoteric as earthling.net, or flyingpurplepeopleeater.com

  8. Now add a DOT between the machine name and the domain name. You will now something like the following EXAMPLE:

leopard.mail.earthling.net

In the above example leopard is the machine name; mail.earthing.net is the domain name.

  1. Once you are satisfied with your work hit F2 to SAVE the file.

  2. Now just REBOOT the machine . If you have done everything correctly you will be rewarded at when you start your konsole with something like:

dcat@leopard~ or if you are root something like root@leopard/home/dcat

Now you will no longer that have the hostname changing at its own whim.

BTW you could have avoided this whole mess during your install as there is a place that allows you to substitute both the machine name and the domain name. Where it read localhost.localdomain you substitute your choices. Choose DHCP and your on your merry way.

WELCOME!!!

D’Cat

I checked my session logs, and it turns out that in fact I used hostnamectl to set my hostname on all the systems I manage. I guess my memory of manually editing /etc/hostname predates my experience with RL.

FWIW, this is an example of why I’m rigorous about doing ALL of my command-line interactions in an SSH shell that automatically leaves a session log in a known place (I use SecureCRT from VanDyke). My memory is always less reliable than an actual session log.

It calls to mind the following venerable:

Confucious say “Most pale ink better than best memory”

I can sympathize I will turn 70 next week. My memory is definitely not as it once was and my Parkinson’s is finally starting to catch up with me. That said Confucious was WRONG: “Most pale ink better than best memory” is only TRUE IF you can READ the pale ink, and my eyesight is starting to fail as well,