Hostname is different vs hostname config file

General support questions
Post Reply
quqonlik
Posts: 16
Joined: 2019/01/19 23:29:32

Hostname is different vs hostname config file

Post by quqonlik » 2019/01/19 23:38:07

I have a question. When I login to my CentOS 7 machine login page hostname is different vs hostname set in /etc/hostname file. Any idea? I have checked /etc/sysconfig/network-script/ifcfg network file as well.

Example:
username@server1 ~$ hostname
apacheserver1


cat /etc/hostname
apacherserver1

Any idea? If I am missing any config files to change? I have cloned this machine from existing and name is till from cloned one.

lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: Hostname is different vs hostname config file

Post by lightman47 » 2019/01/20 13:24:33

There's now a utility for changing hostname (editing the file doesn't work). Use hostnamectl.

Hope this helps.

quqonlik
Posts: 16
Joined: 2019/01/19 23:29:32

Re: Hostname is different vs hostname config file

Post by quqonlik » 2019/01/21 17:45:18

Thank you for your reply. I tried to set using hostnamectl set-hostname "name" and rebooted but seems did not change it. After login in I am still see cloned machine name instead but kernel hostname shows correct hostname . Is there could be any other config file maybe I am forgetting?

Thanks!

lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: Hostname is different vs hostname config file

Post by lightman47 » 2019/01/21 17:51:38

Did you actually use the quotes around the name, or was that just for the post here? (Don't know if it matters).

HOW are you still seeing the old hostname (command used or file name)?

- just curious; it always worked for me -

On mine, I get the proper name when I
hostname
hostnamectl
cat /etc/hostname

quqonlik
Posts: 16
Joined: 2019/01/19 23:29:32

Re: Hostname is different vs hostname config file

Post by quqonlik » 2019/01/21 18:01:06

Hi,

I am using it without quotes as an example. Like: hostnamectl set-hostname apacheserver1 . I tried adding options --transient and --pretty no luck.

kernel.hostname = apacherserver1

Rebooted server and still login page shows hostname as server1

username@server1 ~$

This is really weird or I am missing update any script. Even DNS has set static IP with hostname apacheserver1

lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: Hostname is different vs hostname config file

Post by lightman47 » 2019/01/21 18:08:18

and you ran the hostnamectl command as root or sudo {sorry - gotta ask}

After that, hoping someone else here has further knowledge.

EDIT:
Rereading, it seems 'the problem' is your bash prompt doesn't seem to reflect the true hostname? If this is the case, any chance one of your .bash_{?} files has been edited (perhaps hardcoding the name into the prompt)?

quqonlik
Posts: 16
Joined: 2019/01/19 23:29:32

Re: Hostname is different vs hostname config file

Post by quqonlik » 2019/01/21 18:22:48

Thank you very much for your help. I found the problem in /etc/profile PS1 variable had an old name. This is resolved now.

Thanks

terminator
Posts: 1
Joined: 2019/01/22 17:10:48

Re: Hostname is different vs hostname config file

Post by terminator » 2019/01/22 17:19:21

Hi,

It is recommended that you user system variables, than typing the hostname manually(in ./bash_profile)

i.e
PS1="[$HOSTNAME@:\$PWD]% "
export PS1

gergerdotcom
Posts: 12
Joined: 2019/01/21 04:04:28

Re: Hostname is different vs hostname config file

Post by gergerdotcom » 2019/02/04 06:43:53

hi :)


Image


hope it's alright, but i'm wondering if i can change the Icon name and Chassis after deploying the command hostnamectil? :?:


thanks.

lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: Hostname is different vs hostname config file

Post by lightman47 » 2019/02/04 18:48:42

"man hostnamectl" will answer your questions, and much more.

;-)

Post Reply