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

Re: Should /etc/hostname contain the whole FQDN?



On Fri, Aug 31, 2007 at 11:38:01AM -0500, Jonathan Wilson wrote:
> I have been trying to find out the exact and proper way to set the
> host and domain name on Debian and it's clear as mud. Searching the
> internet gives all sorts of conflicting answers.

Of course.  Debian changes.  UNIX changes.  No to *NIX's are alike.  The
key to knowing the answer comes in understanding the fundamentals.

A host is a host.  One box, one name.  

A network is a network.  One network, one name.

Most hosts are only on one network, however, some hosts are on more than
one network and would then possibly have more than one FQDN.

> 
> "The  host  name is usually set once at system startup in
> /etc/rc.d/rc.inet1 or /etc/init.d/boot (normally by reading the
> contents of a file which contains the host name, e.g.  /etc/hostname)"
> 
> Those first 2 files don't exist on Debian Etch. And thought it says it
> usually gets the hostname from /etc/hostname, that still doesn't tell
> me if that should contain the hostname or the FQDN.
> 
> Then it says "The FQDN of the system is the name that the resolver(3)
> returns for the host name."
> 
> Ok, so what's the resolver?  man 3 resolver returns nothing man
> resolver talks about /etc/resolv.conf.  It does talking about setting
> "domain", then it says search and domain are mutually exclusive. So
> while /etc/resolv.conf may have some effect on the hostname, it surely
> isn't THE way the system gets it's FQDN.

The resolver is the code within libc that maps hostnames to IP
addresses.  That's all.

> 
> Back to hostname man page:
> 
> "Technically: The FQDN is the name gethostbyname(2) returns for the
> host name returned by gethostname(2).  The DNS domain name is the part
> after the first dot."
> 
> (where does gethostbyname(2) and gethostname(2) look?)
> 
> "Therefore it depends on the configuration (usually in /etc/host.conf)
> how you can change it. 

That used to be it, however, with libc6 (or was it 5), that changed to
/etc/nsswitch.conf.  That's Name Service Switch, and has many options.

 
> So that's still not where it's set. Manpage for hosts.conf says multi:
> "If  set to on, the resolv+ library will return all valid addresses
> for a host that appears in the /etc/hosts file, instead of only the
> first."
> 
> So that's how it looks up IP<-> name mappings, but that /still/
> doens't tell me how to set my FQDN.
> 
> Can anyone who /knows/ tell me what the proper officially correct ways
> of setting the hostname and the FQDN are, please?
 

Ok.  So you've named the computer.  You put this hostname (the name up
to but not including the network name(s) to which the box is attached),
in /etc/hostname.

So now /bin/hostname will give you your hostname.  How does hostname -f
give the FQDN?

It asks the resover what the dommain name is.  The resolver consults the
/etc/nsswitch.conf file so see where to look.  On debian, it tells it
that for hosts it should consult files and if it doesn't get an answer,
to consult the DNS via a DNS query to the nameserver that is configured
with files, in this case /etc/resolv.conf.

So, the first place it will look is in /etc/hosts.  It will see, e.g.

192.168.1.5	rocky.hooton	rocky

It will see a FQDN and return rocky.hooton to my hostname -f request.

Now, what if you didn't have this host in /etc/hosts?  What if the only
line was:

127.0.0.1	localhost

?

It would then look in /etc/resolve.conf and see:

nameserver	192.168.1.1

It will then issue a DNS request to 192.168.1.1 asking what the FQDN is
for rocky.

It will be told rocky.hooton.

---

So to finally answer your question, you configure your FQDN wherever you
want names resovled.  If you want it in files on the box itself, then it
goes in /etc/hosts.  If you run your own name server like I do (I run
dnsmasq for simplicity) then you only have to record the information in
one place.

I hope this long-winded answer is of some help.  For more clarity, I'd
suggest __UNIX_System_Administration_Handbook__ by Evi Nemeth, et. al.

Doug.



Reply to: