Re: Revisiting the hostname/FQDN issue, adding libnss-myhostname
Someone (not clear from the web view, and l.d.o does not allow
downloading posts as mbox like the BTS does) wrote:
> why we are writing an /etc/hosts with "127.0.1.1 apollo.example.com apollo"
Hah! *rubs hands* Hostnames on unixoid systems… a pet peeve.
First off, that 127.0.1.1 has to go. There are active changes
underways to change the 127/8 allocation to an 127/24 one, to
free more IPv4 addresses. (Just passing on, don’t talk to me
about this one.)
Then.
/etc/hosts.
I’ve worked best with the following setup:
1. If any IP or Legacy IP address is statically assigned to
the box (“inet static”/“inet6 static” in /e/n/i, or even
it’s known that the host has a reservation on the dhcpd)
then add lines of the form “$ip $fqdn ${fqdn%%.*}"
2. If there is any Legacy IP statically assigned as in 1,
then add additionally “127.0.0.1 localhost”ᵃ,
else add additionally “127.0.0.1 $fqdn ${fqdn%%.*} localhost”ᵇ
3. Add the remaining IP entries like ::1ᶜ
Additionally, /etc/{host,my}name or however the OS calls the fileᵉ
the kernel nodename is loaded from (which will be the result of the
bare “hostname” command without -f/-s) m̲u̲s̲t̲ ̲c̲o̲n̲t̲a̲i̲n̲ ̲t̲h̲e̲ ̲F̲Q̲D̲N̲! This
is not what Debian currently does but is necessary and will lead to
only minor fallout (like the FQDN shown in the too-short field of
KDM’s greeter) that’s easily handled by s/\..*$// in affected code,
but will result in a MUCH better overall operation.
The /etc/domainname or whatever fills the kernel’s domainname must
be empty or nōn-existent, as that’s only used for NIS/YP, which you
don’t use. (If you do, find something that works for you because I
have no setup of that.) This means a bare “domainname” will return
“(none)” or not echo anything (like true(1)).
I also tend to have “search ${fqdn#*.} [other relevant domains]”
in /etc/resolv.conf.
This setup has fixed things like the MTA needing minutes to start
(or to run newaliases) because it could not resolve the hostname,
hostname/domain confusion, etc. It also has the benefit that the
canonical FQDN of the system is ㊀ available at all and independent
of external factors, and ㊁ available without having to do a DNS
query, which has proven massively beneficial (the short hostname
is of course trivially “cut off at the first point”, “hostname -s”).
I almost want to say “let the flames begin”, and Nik will likely
respond that he disagreed years ago with this already, but this is
how I run all unixoid systems (various BSDs, decades of Debian,
SuSE old and new, RHEL and related distros, and the occasional
other unixoid I ran). If this is to be revisited in Debian anyway,
and likely (due to the 127/8 reallocation) needs change anyway, I
wanted to contribute what I personally believe is the best setup.
As such I’ll not take flames (and likely not respond because I’m
not subscribed to d-devel due to the high traffic anyway).
It’s early enough in the release cycle that such a switch and the
fixing of those softwares that need a “cut off” implemented can
still happen.
ⓐ or “127.0.0.1 localhost localhost.localdomain”, though I
only picked up the latterᵈ on GNU systems
ⓑ orᵃ “127.0.0.1 $fqdn ${fqdn%%.*} localhost localhost.localdomain”,
ⓒ I currently am using the following:
::1 ip6-localhost ip6-loopback localhost6 localhost6.localdomain6
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
I picked these up, again, mostly on GNU systems (Debian and RPM kinds)
and dropped bare “localhost” from it; things currently overall tend to
work slightly better if “localhost” only resolves to 127.0.0.1 and not
to ::1 (as well or only). Again, that “localhost6.localdomain6” likely
isn’t neededᵈ
ⓓ In my next overhaul of my “mkhosts” script I’ll probably drop both the
localhost.localdomain and localhost6.localdomain6; one of the “don’t”s
I’ve seen is “localhost{,6}.${fqdn#*.}” which is similarily useless so
do not add that either.
ⓔ “HOSTNAME=host.example.com” in /etc/sysconfig/network on RHEL
So, for the above-mentioned “apollo” system, here’s sample configs.
┌──┤ /etc/hosts when apollo has dynamic IPs (DHCP, rtsol) only:
│
│ 127.0.0.1 apollo.example.com apollo localhost
│
│ ::1 ip6-localhost ip6-loopback localhost6
│ ff02::1 ip6-allnodes
│ ff02::2 ip6-allrouters
└─
┌──┤ /etc/hosts when apollo has static IPs:
│
│ 127.0.0.1 localhost
│ 192.168.1.2 apollo.example.com apollo
│ 172.17.0.1 apollo.example.com apollo
│
│ 2001:db8:0:cafe:: apollo.example.com apollo
│ 2001:db8:0:cafe::0200:5eff:fe00:5300 apollo.example.com apollo
│
│ ::1 ip6-localhost ip6-loopback localhost6
│ ff02::1 ip6-allnodes
│ ff02::2 ip6-allrouters
└─
(The example has an internal (Docker) and an external Legacy IP
static, an EUI64-based IP and the anycast network router.)
┌──┤ /etc/hostname
│
│ apollo.example.com
└─
No /etc/domainname or an empty one.
┌──┤ /etc/resolv.conf
│
│ search example.com example.org
│ nameserver 9.9.9.9
└─
$ cat /proc/sys/kernel/hostname # Linux
apollo.example.com
$ cat /proc/sys/kernel/domainname
(none)
$ sysctl kern.{host,domain}name # BSD
kern.hostname=apollo.example.com
kern.domainname=
Hope this helps.
bye,
//mirabilos
--
“Having a smoking section in a restaurant is like having
a peeing section in a swimming pool.”
-- Edward Burr
Reply to: