Linux host name


when I type hostname in the command prompt, it gives me one name. However, when I go to the host file in ECT it is different. The host file has the correct name. How can this be corrected?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent WSr. Network / Systems AdminCommented:
You can use the hostname command like above but it will not survive a reboot.

If you are using a redhat variant (CentOS, RedHat, Fedora, etc..) you can edit the /etc/sysconfig/network file and add:

Save the file and restart the network services.

This may work on other Linux distros as well, although I don't use debian enough to tell.
In redhat7/centos7/sl7 hostname of /etc/sysconfig/network is ignored as it  gets overridden by /etc/hostname (the later in turn is place to put hostname in Debian etc)
once that done (and /etc/hosts) you can proceed to apply hostname to running system
you can issue hostname command to set new hostname.
now you need to restart services that use old hostname - syslog first, than check logs for old name still popping up.
probably you need to to rejoin AD domain, and update DNS records too

I can change IP of running Linux machine, but since it is your first try - check twice config files, and keep hand on reboot button when renaming services' understanding of machine name.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
@gheist is correct, if you are talking the newer versions of RedHat/CentOS that run systemd.

Good catch Gheist!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Networking

From novice to tech pro — start learning today.