Can someone with far more knowledge than me help here? I have a co-worker with a question; " Where should i set the server's hostname? There seems to be multiple places and i don't understand the differences. 1. # hostname mailserver.mydomain.com 2. # echo "127.0.0.1 mailserver mailserver.mydomain.com">>/etc/hosts 3. # vi /etc/sysconfig/network, add "HOSTNAME=mailserver.mydomain.com" So far i think i understand that postfix likes to see the hostname in the hosts file, but things i have read imply that postfix is pretty clever at working it out from multiple places. Apache also seems to be clever, but the conf file recommends that you hard code the server name into the config. If you don't, where does apache look? If you set the hostname during an install, where is that written? If i use method 1 above ("hostname mailserver.mydomain.com") i seem to have to do that at every boot (or script it of course) whereas the edit to /etc/hosts or /etc/sysconfig/network would survive restarts. I have read the information in "man hostname" and understand that "hostname -f" gets its info from the hosts file, but where does the function "gethostname" get its info from? Finally - which method do you all use to set you hostname? " Thanks all, MrKiwi
MrKiwi spake the following on 11/29/2006 1:34 PM:> Can someone with far more knowledge than me help here? > > I have a co-worker with a question; > " > Where should i set the server's hostname? > There seems to be multiple places and i don't understand the differences. > 1. # hostname mailserver.mydomain.com > 2. # echo "127.0.0.1 mailserver mailserver.mydomain.com">>/etc/hosts > 3. # vi /etc/sysconfig/network, add "HOSTNAME=mailserver.mydomain.com" > > So far i think i understand that postfix likes to see the hostname in > the hosts file, but things i have read imply that postfix is pretty > clever at working it out from multiple places. > Apache also seems to be clever, but the conf file recommends that you > hard code the server name into the config. If you don't, where does > apache look? > If you set the hostname during an install, where is that written? > If i use method 1 above ("hostname mailserver.mydomain.com") i seem to > have to do that at every boot (or script it of course) whereas the edit > to /etc/hosts or /etc/sysconfig/network would survive restarts. > > I have read the information in "man hostname" and understand that > "hostname -f" gets its info from the hosts file, but where does the > function "gethostname" get its info from? > > Finally - which method do you all use to set you hostname? > " > > Thanks all, > > MrKiwiI have my hostname in both /etc/sysconfig/network and /etc/hosts. -- MailScanner is like deodorant... You hope everybody uses it, and you notice quickly if they don't!!!!
/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 127.0.0.1 localhost localhost.localdomain 10.0.0.1 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 10.0.0.1. 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 10.0.0.1 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. -----Original Message----- From: centos-bounces at centos.org [mailto:centos-bounces at centos.org] On Behalf Of Scott Silva Sent: Wednesday, November 29, 2006 2:02 PM To: centos at centos.org Subject: [CentOS] Re: hostname setting MrKiwi spake the following on 11/29/2006 1:34 PM:> Can someone with far more knowledge than me help here? > > I have a co-worker with a question; > " > Where should i set the server's hostname? > There seems to be multiple places and i don't understand thedifferences.> 1. # hostname mailserver.mydomain.com > 2. # echo "127.0.0.1 mailserver mailserver.mydomain.com">>/etc/hosts > 3. # vi /etc/sysconfig/network, add "HOSTNAME=mailserver.mydomain.com" > > So far i think i understand that postfix likes to see the hostname in > the hosts file, but things i have read imply that postfix is pretty > clever at working it out from multiple places. > Apache also seems to be clever, but the conf file recommends that you > hard code the server name into the config. If you don't, where does > apache look? > If you set the hostname during an install, where is that written? > If i use method 1 above ("hostname mailserver.mydomain.com") i seem to > have to do that at every boot (or script it of course) whereas theedit> to /etc/hosts or /etc/sysconfig/network would survive restarts. > > I have read the information in "man hostname" and understand that > "hostname -f" gets its info from the hosts file, but where does the > function "gethostname" get its info from? > > Finally - which method do you all use to set you hostname? > " > > Thanks all, > > MrKiwiI have my hostname in both /etc/sysconfig/network and /etc/hosts. -- MailScanner is like deodorant... You hope everybody uses it, and you notice quickly if they don't!!!! _______________________________________________ CentOS mailing list CentOS at centos.org http://lists.centos.org/mailman/listinfo/centos
Thanks for the correction! I new I couldn't reply to a public forum without making one mistake :) -----Original Message----- From: centos-bounces at centos.org [mailto:centos-bounces at centos.org] On Behalf Of Matt Hyclak Sent: Thursday, November 30, 2006 5:44 AM To: CentOS mailing list Subject: Re: [CentOS] Re: hostname setting 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 youinitially> 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 > 127.0.0.1 localhost localhost.localdomain > 10.0.0.1 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 10.0.0.1. > > There is an order of operations that CentOS uses to resolve hostnames.> 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 10.0.0.1 and not fill ina> /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 -- Matt Hyclak Department of Mathematics Department of Social Work Ohio University (740) 593-1263 _______________________________________________ CentOS mailing list CentOS at centos.org http://lists.centos.org/mailman/listinfo/centos