hostname(7)
๐ NAME ๐
hostname โ the whole lore of how hostnames get resolved, bestie. like, what even IS a hostname and how does the computer figure out where it lives โจ
๐ธ DESCRIPTION ๐ธ
okay so first things first: a hostname is a domain, and a domain is literally just a hierarchical, dot-separated list of subdomains. no cap. so picture the machine monet, chillin' in the example subdomain, which itself lives inside the com domain โ that whole girl gets written out as:
monet.example.com
it's giving address-of-the-machine but make it โจhierarchicalโจ ๐ฆ
each individual element of the hostname has to be from 1 to 63 characters long, and the entire hostname โ dots and all included, yes we're counting the dots โ can be at most 253 characters long. that's the limit, periodt ๐
valid characters for hostnames are ASCII(7) letters from a to z, the digits from 0 to 9, and the hyphen (-). and listen: a hostname may not start nor end with a hyphen. like, hyphen in the middle? cute. hyphen at the edges? absolutely not, the vibe check failed ๐
hostnames are often used with network client and server programs, and those programs must generally translate the name to an address for actual use. (this task is generally performed by either getaddrinfo(3) or the obsolete gethostbyname(3).) so yeah, someone's gotta do the translation and it's usually one of those two ๐
hostnames are resolved by the NSS framework in glibc according to the hosts configuration in nsswitch.conf(5). and the DNS-based name resolver (it lives in the dns NSS service module) resolves them in the following fashion ๐ฅ
๐ the actual resolution tea ๐
- if the name consists of a single component โ that is, it contains no dot โ and the environment variable
HOSTALIASESis set to the name of a file, then that file gets searched for any string matching the input hostname. the file should consist of lines made up of two white-space separated strings: the first one is the hostname alias, and the second one is the complete hostname to be substituted for that alias. and if a case-insensitive match is found between the hostname to be resolved and the first field of a line in that file, then the substituted name is looked up with no further processing. boom, done, no extra steps ๐ซ - if the input name ends with a trailing dot, the trailing dot is removed, and the remaining name is looked up with no further processing. bye dot ๐
- if the input name does not end with a trailing dot, it gets looked up by searching through a list of domains until a match is found. the default search list includes first the local domain, then its parent domains with at least 2 name components (longest first). for example, in the domain
cs.example.com, the namelithium.cchemwill be checked first aslithium.cchem.cs.exampleand then aslithium.cchem.example.com. meanwhilelithium.cchem.comwill not be tried, as there is only one component remaining from the local domain. the search path can be changed from the default by a system-wide configuration file (seeresolver(5)). so like, it's a lil queue of guesses and it stops at the first one that hits ๐
โญ SEE ALSO โญ
getaddrinfo(3)gethostbyname(3)nsswitch.conf(5)resolver(5)mailaddr(7)named(8)- IETF RFC 1123
- IETF RFC 1178
ok that's the whole page, you're officially a hostname scholar now ๐ซถ go forth and resolve responsibly
this little love letter to hostnames ships as part of Linux man-pages 6.20, dated 2026-04-07 โ and that's on periodt ๐๐งโโ๏ธ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: BSD-4-Clause-UC
- Copyright 1987-1993, The Regents of the University of California
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms