From 9053aaad4255a1d01a50f8e44784cd7eebe8f95c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Feb 2016 18:24:03 +0100 Subject: man: change recommended order of NSS modules in /etc/nsswitch.conf So far we recommended placing "nss-mymachines" after "nss-resolve" in the order of preference in /etc/nsswitch.conf. This change reverse this order. Rationale: single-label names are resolved via LLMNR by resolved, which has to time out if no peer by that name exists. By placing "nss-mymachines" first (which always responds immediately) we avoid running into this timeout for most containers. Both modules should return the same data if LLMNR is used by the container anyway. While we are at it, improve the man pages of the three NSS modules in other ways a bit. --- man/nss-myhostname.xml | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'man/nss-myhostname.xml') diff --git a/man/nss-myhostname.xml b/man/nss-myhostname.xml index 251bdecbad..f8837745ae 100644 --- a/man/nss-myhostname.xml +++ b/man/nss-myhostname.xml @@ -57,12 +57,11 @@ Description - nss-myhostname is a plugin for the GNU - Name Service Switch (NSS) functionality of the GNU C Library - (glibc), primarily providing hostname resolution - for the locally configured system hostname as returned by - gethostname2. - The precise hostnames resolved by this module are: + nss-myhostname is a plug-in module for the GNU Name Service Switch (NSS) functionality of + the GNU C Library (glibc), primarily providing hostname resolution for the locally configured + system hostname as returned by + gethostname2. The precise + hostnames resolved by this module are: The local, configured hostname is resolved to @@ -80,7 +79,6 @@ ordered by their metric. This assigns a stable hostname to the current gateway, useful for referencing it independently of the current network configuration state. - Various software relies on an always-resolvable local @@ -93,29 +91,25 @@ changing /etc/hosts is unnecessary, and on many systems, the file becomes entirely optional. - To activate the NSS modules, myhostname - has to be added to the line starting with - hosts: in - /etc/nsswitch.conf. + To activate the NSS modules, add myhostname to the line starting with + hosts: in /etc/nsswitch.conf. - It is recommended to place myhostname - last in the nsswitch.conf line to make sure - that this mapping is only used as fallback, and that any DNS or - /etc/hosts based mapping takes - precedence. + It is recommended to place myhostname last in the nsswitch.conf' + hosts: line to make sure that this mapping is only used as fallback, and that any DNS or + /etc/hosts based mapping takes precedence. Example - Here is an example /etc/nsswitch.conf - file that enables myhostname correctly: + Here is an example /etc/nsswitch.conf file that enables + nss-myhostname correctly: passwd: compat mymachines group: compat mymachines shadow: compat -hosts: files resolve mymachines myhostname +hosts: files mymachines resolve myhostname networks: files protocols: db files -- cgit v1.2.3-54-g00ecf From 63003524cb7c27b50583cc4d90b5d81af5f7a7f6 Mon Sep 17 00:00:00 2001 From: "David R. Hedges" Date: Thu, 18 Feb 2016 21:31:38 -0600 Subject: *.localdomain != localhost ".localdomain" is not a reserved suffix (or prefix). I'm not aware of any product expecting *.localdomain to resolve to localhost, however I am aware of at least one product that defaults to ".localdomain" as its DNS suffix provided via DHCP (pfSense). This leads to unexpected results when attempting to access a host that's offline (or a host that's online, when nsswitch.conf is [mis-]configured to have myhostname ahead of DNS). Operate on: localhost (and localhost.) *.localhost (and *.localhost.) localhost.localdomain (and localhost.localdomain.) *.localhost.localdomain (and *.localhost.localdomain.) We should not cover: *.localdomain (nor *.localdomain.) localdomain (nor localdomain.) --- man/nss-myhostname.xml | 7 ++++--- man/systemd-resolved.service.xml | 7 ++++--- src/basic/hostname-util.c | 10 +++++----- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'man/nss-myhostname.xml') diff --git a/man/nss-myhostname.xml b/man/nss-myhostname.xml index 251bdecbad..e339e6b44e 100644 --- a/man/nss-myhostname.xml +++ b/man/nss-myhostname.xml @@ -71,9 +71,10 @@ is on the local loopback) and the IPv6 address ::1 (which is the local host). - The hostname localhost (as well as any hostname ending in - .localhost, .localdomain or equal to localdomain) is - resolved to the IP addresses 127.0.0.1 and ::1. + The hostnames localhost and + localhost.localdomain (as well as any hostname + ending in .localhost or .localhost.localdomain) + are resolved to the IP addresses 127.0.0.1 and ::1. The hostname gateway is resolved to all current default routing gateway addresses, diff --git a/man/systemd-resolved.service.xml b/man/systemd-resolved.service.xml index 7a9e23a2c6..829729ca09 100644 --- a/man/systemd-resolved.service.xml +++ b/man/systemd-resolved.service.xml @@ -87,9 +87,10 @@ is on the local loopback) and the IPv6 address ::1 (which is the local host). - The hostname localhost (as well as any hostname ending in - .localhost, .localdomain or equal to localdomain) is - resolved to the IP addresses 127.0.0.1 and ::1. + The hostnames localhost and + localhost.localdomain (as well as any hostname + ending in .localhost or .localhost.localdomain) + are resolved to the IP addresses 127.0.0.1 and ::1. The hostname gateway is resolved to all current default routing gateway addresses, diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c index 7bb23448ed..4fe6a725aa 100644 --- a/src/basic/hostname-util.c +++ b/src/basic/hostname-util.c @@ -150,16 +150,16 @@ bool is_localhost(const char *hostname) { assert(hostname); /* This tries to identify local host and domain names - * described in RFC6761 plus the redhatism of .localdomain */ + * described in RFC6761 plus the redhatism of localdomain */ return strcaseeq(hostname, "localhost") || strcaseeq(hostname, "localhost.") || - strcaseeq(hostname, "localdomain.") || - strcaseeq(hostname, "localdomain") || + strcaseeq(hostname, "localhost.localdomain") || + strcaseeq(hostname, "localhost.localdomain.") || endswith_no_case(hostname, ".localhost") || endswith_no_case(hostname, ".localhost.") || - endswith_no_case(hostname, ".localdomain") || - endswith_no_case(hostname, ".localdomain."); + endswith_no_case(hostname, ".localhost.localdomain") || + endswith_no_case(hostname, ".localhost.localdomain."); } bool is_gateway_hostname(const char *hostname) { -- cgit v1.2.3-54-g00ecf