We help IT Professionals succeed at work.

hostname change in linux server

kurajesh asked
i had a hostname for one of my linux server (oel 5.5) and there was a need to change that , hence i changed in /etc/sysconfig/network and also in vi /etc/hosts. rebooted tthe server but still when i open a terminal it shows the old name and hostname also returns the old name.
how to update the hostname correctly

Watch Question

1)  vi   /etc/host  test.human.com  test

2)   /etc/sysconfig/network
active your etho (ethernet adpator)

3) type command service network restart .

5)  check hostname

Most Valuable Expert 2013
Top Expert 2013

hostname newname
Looks like you have already done these steps
Open file /etc/sysconfig/network  using editor Change entry HOSTNAME=XXXXXX to HOSTNAME=New_Host_Name

You may also want to check this entry in /etc/sysconfig/network-scripts/ifcfg-xxx file.  Some times hostname is set in this file.
kurajeshSenior Systems Analyst


Ues farzan I have done the first two already. Need to check you suggestion which I will do it and update soon
kurajeshSenior Systems Analyst


Actually I have done like the following

I have two linux servers namely prod and test
We had to rename test as prod and prod to vision

Renaming of prod to vision happenned successfully whereas test to prod is the issue. I edited in etc/hosts of test and made changes name as prod and rebooted the server. Checked the hostname and returned as test. This is the issue
I just thought explain the real scenario.  
have you tried entering the command on prod after making the changes on /etc/sysconfig/network and /etc/hosts

hostname prod

This sets the hostname on the linux box without rebooting.
If you need them to be persistent across reboots you had them to /etc/sysconfig/network as other experts have pointed.
If you need it to resolve from your linux box you had to /etc/hosts.

Hope it helps,


If you need it to resolve from your linux box you have to edit /etc/hosts* (My bad)

3 of the already posted steps really should work:

1: change /etc/hosts to: localhost
                                prod prod.domain.com
                               prod prod.domain.com

2: change /etc/sysconfig/network to:  HOSTNAME=prod

3: run the command:  hostname prod

4: reboot, just to be 100% sure it sticks.

I have another somewhat convoluted solution that seems to always work when we have this problem. Let me know if it's still not working, and I'll post it next.
Be sure you are not using invalid characters in your host name. So letters, numbers and dashes only.. no underscores, etc.
kurajeshSenior Systems Analyst


i have done all the above inlcuding digus suggestion, but still it returns the same result.

any other idea

When I absolutely can't get anything else at all to work, I use webmin: http://www.webmin.com

After it is installed, login and go to:
the networking tab,
then "Network Configuration"
then "Hostname and DNS Client"
then change the "hostname" box (if it already says prod, just hit save)
then click "Module Index"
then click the "Apply Configuration" button.

It's a hassle, but it has always worked for me when nothing else has. It is also a very nice and simplified GUI for *nix boxes. I just hate to see people use it as a "crutch".

Good Luck!
Most Valuable Expert 2013
Top Expert 2013

Do you have a Domain Name Server?

If so, did you update the DNS tables with the new values?

Do you use DHCP with hostname management?

If so, has the DHCP server's setup been changed accordingly?

Do you use NIS to distribute "hosts.byname" or "hosts.byaddr"?

Check with "ypwhich -m"

If so, does the hosts map contain the new values?

Is your "hostname" command indeed "/usr/bin/hostname"?

Check with "which hostname" or "whence -v hostname" and "alias hostname".

If it's something else try to find out what it does.


kurajeshSenior Systems Analyst


we have a dns server and its ip address has been mentioned in dns config of linux server.
also linux server is having a static ip address.

"ypwhich -m"
ypwhich: can't get local yp domain: Local domain name not set

 which hostname

still the issue persists
You need to set your NIS domain name to "example.com"

Enter the command,
domainname example.com

vi /etc/sysconfig/network
(and enter or edit this line)
NISDOMAIN example.com (I don't remember if there is an equal to between NISDOMAIN and example.com but you can check)

You did not try webmin then.
kurajeshSenior Systems Analyst


I did try webamin and it is installed already. I accessed from my desktop and there in hostname and dns config it shows the right hostname. Absolutely no issues but when I enter hostname in terminal it returns as test itself.
And you have hit save and "apply changes" in webmin, then logged out and back into the server since then? Seems like we may be overlooking something really simple here..

You might try
# grep -iR "old_hostname" /etc/*

and see if the hostname is being set somewhere else as well.

@11bytes - good call!
kurajeshSenior Systems Analyst


hi all,

as digus was saying "Seems like we may be overlooking something really simple here" , right there is an entry in one of the file
 sysctl.conf and there was an entry called kernel.hostname and is was test and chanegd to prod and worked .

thanks a lot guys for your wonderful support.