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

I need to do the hostname changes on a centos server which will serve

What do I need to do in /etc/hosts, /etc/sysconfig/network and with the hostname command?

In /etc/sysconfig/network do I need to write this :

or this :

In /etc/hosts do I need to write this :


or this :


Do I need to do sudo hostname or sudo hostname

Thanks a lot!


Is there something else that I need to setup about hostname?

share|improve this question
i don't even get why anyone would bother to do this stuff. i see a mention below of using hostname -f so i guess you get a properly-functioning hostname command, but what else? – the0ther Jan 11 at 22:58
up vote 9 down vote accepted

/etc/sysconfig/network file is source from which the startup scripts take the arguments for 'hostname' command. And this should be just the machine name, not fully qualified. The domain part is usually defined in the /etc/resolv.conf file.

Assuming the fully qualified host name is '' ('www' doesn't look like a good host name to me), then:

  • /etc/sysconfig/network: HOSTNAME=lemon
  • /etc/resolv.conf (along right 'nameserver' entires): search
  • /etc/hosts (should not be needed if DNS works properly): XXX.XXX.XXX.XXX lemon

If everything is properly configured, then hostname command will return "lemon" and hostname -f will return "".

In your case it would seem the hostname is 'www' in domain ''… I don't think that is exactly what you want. 'www' may be an alias (DNS CNAME)… if you want it in your /etc/hosts file, then just append it to the line with your IP:


The settings from /etc/sysconfig/network will be applied after network is restarted. You may set the hostname immediately with the hostname command. /etc/hosts and /etc/resolv.conf changes are active immediately (except for applications that keep old data cached).

share|improve this answer

your settings should look like this:

  • /etc/sysconfig/network:
  • /etc/hosts: XXX.XXX.XXX.XXX www

you can also call hostname, but this will only change the hostname until you restart your server the next time.

as far as i can remember, these are all changes you have to make.

share|improve this answer
If you put the FQDN in /etc/sysconfig/network then the 'hostname' and 'hostname -f' commands will return the same FQDN value. This is not really correct. 'hostname' should ideally simply return the actual hostname. – Shaun Dewberry Apr 4 '11 at 12:59

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.