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

Re: where is /etc/hosts supposed to come from?

On 2009-12-29 14:09:49 +0100, Jeremiah Foster wrote:
> On one of my machines apticron uses a call to hostname -f, which
> fails, while uname -n succeeds.

"uname -n" doesn't necessarily return the FQDN.

xvii% uname -n
xvii% hostname
xvii% hostname -f
xvii% cat /etc/hostname 

Note in the hostname(1) man page:

  /etc/hostname This file should only contain the hostname and not the
  full FQDN.

> Perhaps it should be a bug to use hostname -f since it unreliable?

When the machine is correctly configured (i.e. really has a FQDN),
"hostname -f" is reliable. But note that this is Debian-specific.

FYI, here's how one can get the FQDN in Perl (gethostbyname is no
longer in POSIX, but it currently works in practice... or perhaps
"hostname" has something more reliable?):

#!/usr/bin/env perl

use strict;
use POSIX;

my $nodename = (POSIX::uname)[1];
print "Nodename: $nodename\n";
print "FQDN: ", (gethostbyname $nodename)[0], "\n";

(You would do the same thing in other languages: uname, then

Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)

Reply to: