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

Re: /etc/hostname



* Tom Allison (tallison@tacocat.net)[20040620 19:41]:
> My /etc/hostname file contains only the machine name and not the FQDN
> of the machine.
>
> This is causing problems with procmail, squirrelmail and probably 50
> other things out there.
>
> How do I set this once and for all?
> And should it be a FQDN or just the machine name?

the machine's hostname should just be a hostname.  I'm not
sure if you can understand any python, but here's some code
to find the FQDN, which I think helps illustrate just what
an FQDN really is:

def fqdn():
        print socket.gethostbyaddr(socket.gethostbyname(socket.gethostname()))[0]

So as you can see, the fqdn is determined by a combination
of the machine's hostname and it's resolver configuration.
Most machines are set by default to use the /etc/hosts file
first, and DNS as a fallback.

Let me use a couple of examples from machines I work with.
I have a machine at home named gobo.  The hostname is gobo.
gethostbyname(gobo) returns 127.0.0.1.
gethostbyaddr(127.0.0.1) returns gobo.doorstop.net.  So the
machine's fqdn is gobo.doorstop.net.  There is no DNS server
serving names on my home LAN, so all name <=> address
mappings are set up in /etc/hosts files.  Gobo's /etc/hosts
has a line like this:

127.0.0.1       gobo.doorstop.net gobo localhost

This accomplishes all of the magic shown above.  In reality,
gobo has multiple addresses, and there are multiple lines
that include "gobo", and they include long names qualified
by different domains (e.g. "192.168.16.16 gobo.home gobo").
What matters here is the first line that matches "gobo", and
that's the 127.0.0.1 line.  The next thing that matters is
the first name on that line: gobo.doorstop.net.  When the
system tries to get a name from an address, it can get
multiple results.  The first one is used as the FQDN.

Another example is my machine at work.  Here a local
nameserver provides forward and reverse name resolution.  My
own machine's name does not appear in its /etc/hosts file.
Instead, gethostbyname(gethostname()) gets an address via
DNS.  Again, gethostbyaddr() makes a reverse DNS query on
this result and returns the FQDN.

So the short answer to your question is to set your hostname
to a short name (no dots) and set up your name resolution to
be able to provide the FQDN when needed.  Most likely, this
means adding your name in /etc/hosts.

good times,
Vineet

Attachment: pgpLSW1Rcfjqi.pgp
Description: PGP signature


Reply to: