{"id":3495,"date":"2022-12-20T17:08:49","date_gmt":"2022-12-20T20:08:49","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/nssmyhostname-man8\/"},"modified":"2022-12-20T17:08:49","modified_gmt":"2022-12-20T20:08:49","slug":"nssmyhostname-man8","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/nssmyhostname-man8\/","title":{"rendered":"NSS&minus;MYHOSTNAME (man8)"},"content":{"rendered":"<h1 align=\"center\">NSS\u2212MYHOSTNAME<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#EXAMPLE\">EXAMPLE<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">nss-myhostname, libnss_myhostname.so.2 \u2212 Hostname resolution for the locally configured system hostname<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">libnss_myhostname.so.2<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>nss\u2212myhostname<\/b> is a plug\u2212in module for the GNU Name Service Switch (NSS) functionality of the GNU C Library (<b>glibc<\/b>), primarily providing hostname resolution for the locally configured system hostname as returned by <b>gethostname<\/b>(2). The precise hostnames resolved by this module are:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 The local, configured hostname is resolved to all locally configured IP addresses ordered by their scope, or \u2014 if none are configured \u2014 the IPv4 address 127.0.0.2 (which is on the local loopback) and the IPv6 address ::1 (which is the local host).<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 The hostnames &#8220;localhost&#8221; and &#8220;localhost.localdomain&#8221; (as well as any hostname ending in &#8220;.localhost&#8221; or &#8220;.localhost.localdomain&#8221;) are resolved to the IP addresses 127.0.0.1 and ::1.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 The hostname &#8220;_gateway&#8221; is resolved to all current default routing gateway addresses, ordered by their metric. This assigns a stable hostname to the current gateway, useful for referencing it independently of the current network configuration state.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Various software relies on an always\u2212resolvable local hostname. When using dynamic hostnames, this is traditionally achieved by patching \/etc\/hosts at the same time as changing the hostname. This is problematic since it requires a writable \/etc file system and is fragile because the file might be edited by the administrator at the same time. With <b>nss\u2212myhostname<\/b> enabled, changing \/etc\/hosts is unnecessary, and on many systems, the file becomes entirely optional.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">To activate the NSS modules, add &#8220;myhostname&#8221; to the line starting with &#8220;hosts:&#8221; in \/etc\/nsswitch.conf.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">It is recommended to place &#8220;myhostname&#8221; either between &#8220;resolve&#8221; and &#8220;traditional&#8221; modules like &#8220;files&#8221; and &#8220;dns&#8221;, or after them. In the first version, well\u2212known names like &#8220;localhost&#8221; and the machine hostname are given higher priority than the external configuration. This is recommended when the external DNS servers and network are not absolutely trusted. In the second version, external configuration is given higher priority and <b>nss\u2212myhostname<\/b> only provides a fallback mechanism. This might be suitable in closely controlled networks, for example on a company LAN.<\/p>\n<h2>EXAMPLE <a name=\"EXAMPLE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Here is an example \/etc\/nsswitch.conf file that enables <b>nss\u2212myhostname<\/b> correctly:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">passwd: compat systemd <br \/> group: compat systemd <br \/> shadow: compat<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"># Either (untrusted network): <br \/> hosts: mymachines resolve [!UNAVAIL=return] <b>myhostname<\/b> files dns <br \/> # Or (only trusted networks): <br \/> hosts: mymachines resolve [!UNAVAIL=return] files dns <b>myhostname<\/b> <br \/> networks: files<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">protocols: db files <br \/> services: db files <br \/> ethers: db files <br \/> rpc: db files<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">netgroup: nis<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">To test, use <b>glibc<\/b>&#8216;s <b>getent<\/b> tool:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">$ getent ahosts \u2018hostname\u2018 <br \/> ::1 STREAM omega <br \/> ::1 DGRAM <br \/> ::1 RAW <br \/> 127.0.0.2 STREAM <br \/> 127.0.0.2 DGRAM <br \/> 127.0.0.2 RAW<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In this case, the local hostname is <i>omega<\/i>.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>systemd<\/b>(1), <b>nss-systemd<\/b>(8), <b>nss-resolve<\/b>(8), <b>nss-mymachines<\/b>(8), <b>nsswitch.conf<\/b>(5), <b>getent<\/b>(1)<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  nss-myhostname, libnss_myhostname.so.2 \u2212 Hostname resolution for the locally configured system hostname <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,52,4,617],"class_list":["post-3495","post","type-post","status-publish","format-standard","hentry","category-8-administracion-del-sistema","tag-5","tag-administracion","tag-man8","tag-nss-myhostname"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=3495"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3495\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=3495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=3495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=3495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}