LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 06-02-2019, 12:07 AM   #1
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Rep: Reputation: 190Reputation: 190
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


Any help is appreciated.
 
Old 06-02-2019, 01:57 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
wouldn't this be sufficient?
Code:
ls -al /etc/hostname 
-rw-r--r-- 1 root root 5 Oct 15  2014 /etc/hostname
 
Old 06-02-2019, 02:02 AM   #3
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Original Poster
Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by ondoho View Post
wouldn't this be sufficient?
Code:
ls -al /etc/hostname 
-rw-r--r-- 1 root root 5 Oct 15  2014 /etc/hostname

that gives me
Code:
-rw-r--r-- 1 root root 7 Feb 18 23:34 /etc/hostname

but it has to have been after that as my uptime is definitely shorter.
Code:
 00:00:35 up 4 days,  3:36,  0 users,  load average: 1.14, 1.07, 0.97
 
Old 06-02-2019, 02:10 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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?
 
1 members found this post helpful.
Old 06-02-2019, 12:55 PM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,748

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
From man hostname (emphasis added)
Code:
   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
Code:
hostname -F /etc/hostname
to change it back

Last edited by scasey; 06-02-2019 at 12:58 PM.
 
Old 06-02-2019, 02:05 PM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,832

Rep: Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219
Any hints in /var/log/messages?
 
Old 06-02-2019, 02:22 PM   #7
WideOpenSkies
Member
 
Registered: May 2019
Location: /home/
Distribution: Arch Linux
Posts: 166

Rep: Reputation: 61
Can't you directly edit the hostname file?
 
Old 06-02-2019, 02:49 PM   #8
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Original Poster
Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by ondoho View Post
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.
 
Old 06-02-2019, 02:52 PM   #9
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,748

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Quote:
Originally Posted by TheEzekielProject View Post
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?
 
1 members found this post helpful.
Old 06-02-2019, 03:57 PM   #10
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Original Poster
Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by scasey View Post
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
 
Old 06-03-2019, 08:39 AM   #11
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,832

Rep: Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219
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!
 
Old 06-03-2019, 05:31 PM   #12
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Original Poster
Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by MadeInGermany View Post
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
 
Old 06-04-2019, 01:19 AM   #13
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by TheEzekielProject View Post
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.
if it happens again, investigate again.
you know a little more already.
btw, the current shell's environment can be checked with
Code:
env
you should also have checked the actual content of /etc/hostname of course.
 
Old 06-04-2019, 01:30 AM   #14
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

Quote:
Originally Posted by TheEzekielProject View Post
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 View Post
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.

Evo2.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RHEL changed the w default options in 7!!! Is there a way to get them back? abefroman Linux - Newbie 2 03-29-2015 12:10 PM
HOSTNAME = hostname -> HOSTNAME: command not found ? thomas2004ch Linux - Software 2 08-26-2013 08:25 PM
Changed hostname during install, now CUPS has wrong hostname on web interface slinx Linux - Software 1 08-07-2009 08:01 PM
Installed Ubuntu but it changed my boot loader. I want this changed... mdorries Linux - Distributions 8 05-31-2007 08:13 PM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:54 AM.

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