[CentOS] Re: hostname setting

Matt Hyclak hyclak at math.ohiou.edu
Thu Nov 30 13:44:06 UTC 2006

On Wed, Nov 29, 2006 at 02:20:03PM -0800, Ian Anderson enlightened us:
> /etc/sysconfig/network is what assigns the hostname to your particular
> server. This is also where CentOS writes the hostname when you initially
> install the OS. 
> /etc/hosts provides a mechanism for mapping that hostname to an IP
> address.  This is one of several ways to map ip's to hostnames.    
> I use /etc/sysconfig/network to "name" my machines and then enter that
> value into /etc/hosts.   i.e. 
> /etc/sysconfig/network
> HOSTNAME="vpn-gateway"
> /etc/hosts
> localhost localhost.localdomain
> vpn-gateway vpn-gateway.mydomain.com 
> the second entry is an "alias" to vpn-gateway.  If you were to ping
> either one you would get a response from
> There is an order of operations that CentOS uses to resolve host names.
> By default the first attempt is in the hosts file. If it doesn't find
> anything there is will try DNS, if nothing is there it will try WINS,
> and so on.  If you have a DNS server in your network you could add a
> record to resolve vpn-gateway.mydomain.com to and not fill in a
> /etc/hosts value at all.  (Providing /etc/resolv.conf is setup to look
> at that DNS server)  
> Someone correct me if I am wrong, but this is what I understand to be
> correct. 

Not to pick nits, but according to the hosts manpage, you have your aliases
and FQDN's backwards:

For each host a single line should be present with the following information:

              IP_address canonical_hostname aliases

And it is /etc/nsswitch.conf that determines the order of search. By default
this is files (e.g. /etc/hosts) then dns, and there may be others like ldap
or nis depending on how you set up the machine.


Matt Hyclak
Department of Mathematics 
Department of Social Work
Ohio University
(740) 593-1263

More information about the CentOS mailing list