Is there a way to check when the hostname was changed?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Is there a way to check when the hostname was changed?
Hello all,
Basically title. I tried googling but could only find results on how to change the hostname, which I know how to do. But somehow my hostname has been changed (since last reboot, during the current session. I have one terminal showing my expected hostname, and the one I just opened showing as "new-host-2"). I'd like to know when and how it happened. I am the only user of this computer
I think it's possible to change this dynamically via environment variable.
Have you checked? as always, more detail is required.
Can you reboot the server to see if the stray hostname goes away? does every new terminal now have the new hostname?
SET NAME
When called with one argument or with the --file option, the commands set the host name or the NIS/YP domain name. hostname uses the sethostname(2) function, while all of the three domainname, ypdomainname and nisdomainname
use setdomainname(2). Note, that this is effective only until the next reboot. Edit /etc/hostname for permanent change.
Note, that only the super-user can change the names.
So it appears that a reboot will put it back, or you can just do
I think it's possible to change this dynamically via environment variable.
Have you checked? as always, more detail is required.
Can you reboot the server to see if the stray hostname goes away? does every new terminal now have the new hostname?
So looking through the various /var/log/messages* files the change happened between /var/log/messages.1 and /var/log/messages.2.gz. The expected hostname last appears at the end of /var/log/messages.2.gz on May 28 20:44:28 and the changed name appears at the start of /var/log/messages.1 on May 28 21:52:09. I didn't see the change specifically mentioned in the logs, though I'm not sure if that would even appear here.
I have not recently edited anything that should affect environment variables though I am not sure where all they can be set from. I have checked /etc/environment, .bashrc, and .profile.
Yes every new terminal showed the new hostname.
I did reboot and now the expected hostname is shown. I just thought it strange to have changed, I haven't had it changed unexpectedly before.
I have one terminal showing my expected hostname, and the one I just opened showing as "new-host-2"). I'd like to know when and how it happened. I am the only user of this computer
.
By “showing” are you talking about what the terminal displays on its widow title?
What does the host name command return in that terminal?
By “showing” are you talking about what the terminal displays on its widow title?
What does the host name command return in that terminal?
I am talking about how it shows username@hostname, hostname was showing new-host-2 rather than my usual hostname. Not in the window title, (though it did show there as well) but the terminal itself. The hostname command showed new-host-2 in that terminal. But a reboot has made this go away. Still curious as to how it happened though
Likely a command "hostname new-host-2" was run.
If it happened between two logfiles then check the rotation scripts in /etc/logrotate.d/ or any script that runs at the same time, e.g. in /etc/cron.daily/.
Last but not least, check /var/log/secure!
Likely a command "hostname new-host-2" was run.
If it happened between two logfiles then check the rotation scripts in /etc/logrotate.d/ or any script that runs at the same time, e.g. in /etc/cron.daily/.
Last but not least, check /var/log/secure!
I checked my .bash_history and no such command was run. I also ran a grep -rnw for "hostname" on /etc/logrotate.d/, /etc/cron.daily/, /etc/cron.weekly/, and /etc/cron.monthly which turned up no results. And /var/log/secure does not exist on my system
I checked my .bash_history and no such command was run. I also ran a grep -rnw for "hostname" on /etc/logrotate.d/, /etc/cron.daily/, /etc/cron.weekly/, and /etc/cron.monthly which turned up no results.
The hostname can sometimes be provided by dhcp a server. Has your machine been on a new network?
Quote:
Originally Posted by TheEzekielProject
And /var/log/secure does not exist on my system
On Debian based machines /var/log/auth.log is similar to /var/log/secure in RHEL land.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.