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

Re: set domain name in Debian `



On Fri, 11 Nov 2016, Glenn English wrote:
> /proc/sys/domainname says "(none)". hostname -f gives the old domain

/proc/sys/domainname is the kernel's idea of a domain name, which is
only used by some network filesystems (kernel-based NFS, I think),
AFAIK.

Nothing else needs it.  And if you set up such a filesystem, the
userspace utilities should set the kernel domainname properly by
themselves.

Note that the kernel also needs to know the node name (host name without
a domain)... and _this_ is used everywhere.

> name (where does it get it). grep -ir doesn't find the old name string
> anywhere in /etc or in /lib.

hostname -f does this:

1. Asks glibc for the hostname, using gethostname().

2. Does an IP lookup on the hostname, using getaddrinfo() and the
   hostname it got from gethostname(), and returns the result from
   getaddrinfo().

Since it uses glibc for the host name lookup, it is subject to the glibc
name resolver, which is configured through /etc/nsswitch.conf.

Now, gethostname() works like this [in glibc]: it calls the uname()
syscall, and uses the node name returned.  I.e. it looks up the
*hostname* the kernel was set to.

So, glibc's gethostname() will match the output of "uname -n".  This
information was set on the kernel by either systemd, or by the
initscripts.

Initscripts use /etc/hostname to set this information.  I am not well
versed on how exactly systemd persists this information, but it likely
uses /etc/hostname as well.

> I know it must be simple to do -- the installer does it without
> downloading a C library, but it must be in a secret place I don't know
> about...

1. Set /etc/hostname to the *node name* (i.e. just the host name,
   without the domain)

2. Ensure the *node name* _locally_ resolves to an IPv4/IPv6.  Usually
   this is done by adding it to /etc/hosts, so that things will not
   break when the network is down.

   Do it like this in /etc/hosts:
   <ip> <fully qualified hostname> <nodename>

   For example:

   /etc/hostname:
   examplehost

   /etc/hosts:
   192.0.2.42  examplehost.example.com  examplehost

   Refer to the item (3) below for the reasoning.

   Full answer:  anything that is resolvable locally when piped by
   glibc through the "hosts" nss module pipeline configured in
   /etc/nsswitch.conf will do.  /etc/hosts is a configuration
   file processed for the "files" nss module typically used in
   /etc/nsswitch.conf.

3. Ensure the IPv4/IPv6 you used for the *node name* resolves to
   the full host name (FQDN).

   Now, there is a trick to doing this when using /etc/hosts.  You
   *must* list the FQDN first in /etc/hosts, as it will return just the
   first match when doing a "reverse lookup".

   The complete answer is: ensure the "hosts" nss module pipeline
   configured in /etc/nsswitch.conf will return as the *first* match,
   for the *node name*'s IPv4/IPv6, the FQDN of the host.


There, this is a bit harder to understand than other answers you got,
but it should get the details right and might be helpful in more
convoluted scenarios.

"man nsswitch.conf" for mode details about /etc/nsswitch.conf.
"man hosts" for more details about /etc/hosts

and each libc function I mentioned also has its own manpage.

-- 
  Henrique Holschuh


Reply to: