Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On CentOS (5.x) I have a VPS that has hostname set to "", at least this is the domain I am getting when typing "hostname" command.

I want to change it to 'localhost.localdomain' because I think it is more generic and reliable.

localhost.localdomain already exists in these files: /etc/sysconfig/network AND /etc/hosts



# Do not remove the following line, or various programs
# that require network functionality will fail.               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6

So next I tried these commands:

hostname localhost.localdomain


hostname -v localhost.localdomain

"hostname" command now returns this new value. But after restart it changes back to or at least this is the "hostname" command returns.

Anything else to edit?

share|improve this question
Did you changed the /etc/hostname too ? – clmssz Jan 11 '12 at 15:52
Is NetworkManager enabled? If so, NM will sometimes interfere with your manual configuration. Do a chkconfig NetworkManager --list to see if it is enabled. – Stefan Lasiewski Jan 11 '12 at 17:08
It says: NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off – adrianTNT Jan 11 '12 at 22:15
@spud you mean /etc/hosts file? I did not edit it because it already contains "localhost.localdomain" there. – adrianTNT Jan 11 '12 at 22:17

Add the following lines into your /etc/sysctl.conf configuration file.

kernel.hostname = hostname
kernel.domainname =

And execute the command sysctl -p /etc/sysctl.conf to read and apply the changes of your /etc/sysctl.conf configuration file.

share|improve this answer
Would this be correct? kernel.hostname = localhost; kernel.domainname = localhost.localdomain – adrianTNT Jan 11 '12 at 22:24
Not really. First, the semi-colon is not required. Second, each parameter should be on its own line. Third, it doesn't make sense for having a FQHN of "localhost.localhost.localdomain". – bintut Jan 12 '12 at 3:17

Did you edit the /etc/sysconfig/network file? Or are you just showing it's contents? The hostname command does not actually edit these files. When the system starts the init scripts read the host name from the configuration files and this setting is then passed to the hostname command. In additoion as mentioned by other posts be sure to edit your hosts file so that the mapping for your hostname <-> ip is correct on the local host.

More information is available in the Red Hat documentation

Also are you using Network Manager to manage your network interfaces? If so you will need to go into NM and make sure the settings jive there as well.

share|improve this answer
I was not using network manager. I was able to solve this after editing the two config files to a different value then rebooted, then changed back to localhost.localdomain and it remained like that. Thanks. – adrianTNT Jan 12 '12 at 10:12
up vote 2 down vote accepted

I didn't edit the files /etc/sysconfig/network and /etc/hosts because these already contained the hostname I wanted (localhost.localdomain), so just by command hostname localhost.localdomain it didn't remain saved after reboot.

But then my host edited these two files to a different host name, rebooted the server (without any other command, just editing) and the new hostname applied and remained changed. Then I edited files again and set them to localhost.localdomain as they are on some other of my VPS and now they updated and remained to localhost as I wanted.

share|improve this answer

Pretty sure /etc/sysconfig/network is depreciated, try /etc/sysconfig/networking/profiles/default/hosts and /etc/sysconfig/networking/profiles/default/network

share|improve this answer
/etc/sysconfig/networking/profiles/default/hosts is same as above hosts (no old_domain in it), and the second one doesn't exist: /etc/sysconfig/networking/profiles/default/network – adrianTNT Jan 11 '12 at 15:23
/etc/sysconfig/network is not deprecated. This is the correct place to put some settings. See… – Stefan Lasiewski Jan 11 '12 at 17:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.