Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to do the hostname changes on a centos server which will serve www.myserver.com

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 :

HOSTNAME=www.myserver.com

or this :

HOSTNAME=myserver.com

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

XXX.XXX.XXX.XXX     myserver.com

or this :

XXX.XXX.XXX.XXX     wwww.myserver.com www

Do I need to do sudo hostname www.myserver.com or sudo hostname myserver.com?

Thanks a lot!

UPDATE :

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

share|improve this question

2 Answers 2

up vote 8 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 'lemon.example.com' ('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 example.com
  • /etc/hosts (should not be needed if DNS works properly): XXX.XXX.XXX.XXX lemon.example.com lemon

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

In your case it would seem the hostname is 'www' in domain 'myserver.com'… 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:

XXX.XXX.XXX.XXX lemon.example.com lemon www.myserver.com

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: HOSTNAME=www.myserver.com
  • /etc/hosts: XXX.XXX.XXX.XXX wwww.myserver.com 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
2  
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

 
discard

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.