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

Proposed new scheme for resolving the system hostname



Now that sarge is out the door I'd like to fix the problem of local
hostname resolution so that it works properly for all systems,
including mobile ones.

First of all, the system hostname should always be its own canonical
hostname in the sense of hosts(5), unless the system has a static
domain name, in which case the canonical hostname should be the FQDN
formed from the system hostname and the domain name.

Accordingly, the canonical host name of the system should never be
'localhost.localdomain'; accordingly the system hostname should never
resolve to IP address 127.0.0.1 whose canonical host name is and will
remain 'localhost.localdomain'.  Accordingly, the system hostname
should never be included as an alias for 'localhost.localdomain'.
(This means that netcfg should be changed; see below.)

The system hostname should resolve either to the primary NIC's static
IP address (if there is one) or to the address returned by DNS (if
this is available) or to 127.0.1.1 (failing both of the above).

Obtaining this behavior shouldn't require running a local nameserver and
shouldn't require updating /etc configuration files on the fly.  It
should also work properly when the system hostname is set dynamically
after being assigned by a DHCP server.

In order to satisfy these desiderata I propose that the following
scheme be implemented.

A1. The installer writes an /etc/nsswitch.conf file that contains:

    hosts: files dns defaults

A2. We create a new NSS module called "defaults" which simply resolves
the local hostname to IP address 127.0.1.1 which has as its canonical
hostname the system hostname.

A3. netcfg changes so that when it writes /etc/hosts it never puts the
system hostname in as an alias for 'localhost.localdomain'.  If the
system lacks a permanent NIC with static IP address then the hostname
is omitted from /etc/hosts altogether.

With this scheme implemented, a mobile computer not connected to the
network and with no local nameserver running gets its hostname resolved
to 127.0.1.1 using the "defaults" service.  The same machine connected
to the network via DHCP may be able to resolve its own hostname via
DNS using a combination DHCP/DNS server.  The DNS address overrides
the default address.  DNS can in turn be overridden using /etc/hosts
entries.

For background, see #247734.

NSS package maintainers: Any volunteers to hack up libnss-defaults?


An easier alternative would be:

B1. The installer writes an /etc/nsswitch.conf file that contains:

    hosts: dns files

B2. netcfg changes so that when it writes /etc/hosts it never puts the
system hostname in as an alias for 'localhost.localdomain'.  The system
hostname is always listed on its own line in /etc/hosts.  If the system
lacks a permanent NIC with static IP address then 127.0.1.1 is used
instead.

The disadvantages of scheme B in comparison with scheme A are:
* /etc/hosts can't be used to shortcircuit DNS lookups
* If the system hostname is set dynamically and /etc/hosts isn't updated
dynamically then the system hostname must be resolvable via DNS.

-- 
Thomas Hood <jdthood@aglu.demon.nl>



Reply to: