/etc/hosts , /etc/sysconfig/network and hostname?
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?
Solution 1:
/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).