Should /etc/hostname contain the whole FQDN?

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.

First, I thought the way to do it was to put the FQDN in /etc/hostname. Then I
ended up with host.domain.domain.tld (maybe I caused that some other way).

I looked at the default in a variety of Debian systems that I've setup using
only thing installer defaults to configure the hostname. Some had only the
hostname in /etc/hosts, some had the FQDN.

I've read the hostname manpage. It says clearly:

"It is not possible to set the FQDN or the DNS domain name with the
dnsdomainname command"

Then it says

"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.

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. Usually (if the hosts file is parsed before DNS or NIS) you
can change it in /etc/hosts."

My /etc/host.conf contains this:

multi on

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?

Thanks,

JW

--

5
Average: 5 (1 vote)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Should /etc/hostname contain the whole FQDN?

On Fri, 31 Aug 2007, Jonathan Wilson wrote:

>
> Can anyone who /knows/ tell me what the proper officially correct ways of
> setting the hostname and the FQDN are, please?
>
> Thanks,
>
> JW
>
>
> --

in /etc/hostname :
myhostname
in /etc/hosts:
10.0.0.120 myhostname.mydomain.com myhostname

set those then run /etc/init.d/hostname.sh as root, this gets ran at boot
up, but you can run it and reset the hostname this way.

now when I run hostname -f I get my FQDN, you'll have to restart any
services that rely on this as well after changing it.

-+-
8 out of 10 Owners who Expressed a Preference said Their Cats Preferred Techno.

--

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.

--

Syndicate content