[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Showstopping bug: gethostname() behaving incorrectly



On Wed, Feb 09, 2000 at 11:35:53PM -0700, Jason Gunthorpe wrote:
> 
> On Wed, 9 Feb 2000, Randolph Chung wrote:
> 
> > Many other linux distros put the FQDN in /etc/hostname. Debian doesn't do
> > that. As the man page points out, gethostname behaves like uname -n, which
> > in turn just reads the value set by hostname.
> 
> This seems to be quite random, I checked a bunch of boxes here at the
> univ, Solaris, OpenBSD and HP-UX - they all return an unqualified name for
> gethostname - however some people report that other Solaris, OpenBSD and
> HP-UX boxes don't do this.

Solaris uses /etc/nodename, which is set up at system install;
however, it just uses a user-entered value, so you can use FQDN or
host component as you choose. uname -n also uses the FQDN though, if
you have the FQDN in /etc/nodename at boot. So uname -n and hostname
are consistent. I would suspect that at least some other commercial
Unices are the same.

> I guess it is up to whoever set them up, but it is certianly not uncommon
> to have only the node name in /etc/hostname

I personally prefer the kernel hostname to be set to the desired FQDN;
vagaries of subdomain search paths and multiple interfaces can make
using DNS to determine FQDN rather subideal. Also, many programs rely
on it being set up like that (look at tcsh, for example: %m and %M are
supposed to be the host component and the FQDN respectively. That
doesn't work with them set this way).

Take note that the hostname command has both -f and -s, so you can use
either default and always get what you want by always using -f or -s;
because the host component can always be found deterministically from
the FQDN, but not vice-versa, I would recommend using the FQDN as the
default.

All programs that want a specific form of answer from gethostname
really do need to make sure they get it, and not trust gethostname.

-- 
Elie Rosenblum                 That is not dead which can eternal lie,
http://www.cosanostra.net   And with strange aeons even death may die.
Admin / Mercenary / System Programmer             - _The Necronomicon_


Reply to: