HOSTNAME(1)

๐ŸŽ€ HOSTNAME(1) ๐ŸŽ€ โ€” Linux Programmer's Manual

โœจ NAME โœจ

okay so hostname is literally the Unix command for showing or setting the system's host name ๐Ÿ’– but it's got cousins too, bestie ๐Ÿงš:

  • domainname โ€” show or set the system's NIS/YP domain name
  • ypdomainname โ€” show or set the system's NIS/YP domain name
  • nisdomainname โ€” show or set the system's NIS/YP domain name
  • dnsdomainname โ€” show the system's DNS domain name

๐Ÿ’… SYNOPSIS ๐Ÿ’…

hostname [-a|--alias] [-d|--domain] [-f|--fqdn|--long] [-A|--all-fqdns]
[-i|--ip-address] [-I|--all-ip-addresses] [-s|--short] [-y|--yp|--nis]
hostname [-b|--boot] [-F|--file filename] [hostname]
hostname [-h|--help] [-V|--version]

domainname [nisdomain] [-F file]
ypdomainname [nisdomain] [-F file]
nisdomainname [nisdomain] [-F file]

dnsdomainname

๐ŸŒธ DESCRIPTION ๐ŸŒธ

ngl, hostname is how you check the system's DNS name, and also how you peek at or change its hostname or NIS domain name ๐Ÿซถ

๐Ÿ”ฎ GET NAME

when you call it with no arguments, it just shows you the current names, periodt โœจ

hostname prints the name of the system as returned by the gethostname(2) function.

domainname prints the NIS domainname of the system. domainname uses the gethostname(2) function, while ypdomainname and nisdomainname use the getdomainname(2).

dnsdomainname prints the domain part of the FQDN (Fully Qualified Domain Name). The complete FQDN of the system comes back with hostname --fqdn (but see the warnings in section THE FQDN below) ๐Ÿ‘€

๐ŸŽฏ SET NAME

when you call it with one argument or with the --file option, these commands set the host name or the NIS/YP domain name ๐Ÿ”ฅ hostname uses the sethostname(2) function, while all three of domainname, ypdomainname and nisdomainname use setdomainname(2). Heads up: this is only effective until the next reboot. For a permanent change, edit /etc/hostname ๐Ÿ™ˆ

Only the super-user can change the names, so don't even try it as a regular user ๐Ÿ’€

It is not possible to set the FQDN or the DNS domain name with the dnsdomainname command (see THE FQDN below) ๐Ÿšซ

The host name is usually set once at system startup in /etc/init.d/hostname.sh (normally by reading the contents of a file which contains the host name, e.g. /etc/hostname) ๐ŸŒˆ

๐Ÿฆ‹ THE FQDN

the FQDN (Fully Qualified Domain Name) of the system is the name that resolver(3) returns for the host name, such as ursula.example.com. It's usually the hostname followed by the DNS domain name (the part after the first dot). You can check the FQDN with hostname --fqdn, or the domain name with dnsdomainname ๐Ÿ’œ

You cannot change the FQDN with hostname or dnsdomainname.

the recommended way to set the FQDN is to make the hostname an alias for the fully qualified name using /etc/hosts, DNS, or NIS. For example, if the hostname was "ursula", you might have a line in /etc/hosts that reads:

127.0.1.1    ursula.example.com ursula

technically: the FQDN is the name getaddrinfo(3) returns for the host name returned by gethostname(2). The DNS domain name is the part after the first dot.

so how you change it depends on how your resolver is configured (usually in /etc/host.conf). The hosts file is usually parsed before DNS or NIS, so it's most common to change the FQDN in /etc/hosts ๐Ÿงš

Warning, bestie: if a machine has multiple network interfaces/addresses or is used in a mobile environment, it may have multiple FQDNs/domain names or none at all. So avoid hostname --fqdn, hostname --domain and dnsdomainname. hostname --ip-address has the same limitations, so avoid that one too ๐Ÿ˜ญ

๐Ÿ“ OPTIONS ๐Ÿ“

  • -a, --alias โ€” shows the alias name of the host (if used). This one is deprecated, so don't use it anymore ๐Ÿ’€
  • -A, --all-fqdns โ€” shows all FQDNs of the machine. It goes through every configured network address on every configured network interface and translates them to DNS domain names. Addresses that can't be translated (like ones without a proper reverse IP entry) get skipped. Different addresses may resolve to the same name, so the output can have duplicates. Don't make any assumptions about the order of the output ๐ŸŒธ
  • -b, --boot โ€” always sets a hostname. This lets the file given by -F be non-existent or empty, in which case the default hostname localhost is used if none is set yet ๐Ÿซถ
  • -d, --domain โ€” shows the name of the DNS domain. Don't use the command domainname for this, because it shows the NIS domain name, not the DNS one. Use dnsdomainname instead. See the warnings in section THE FQDN above, and honestly, just avoid this option ๐Ÿ™ˆ
  • -f, --fqdn, --long โ€” shows the FQDN (Fully Qualified Domain Name). A FQDN is a short host name plus the DNS domain name. Unless you're using bind or NIS for host lookups, you can change the FQDN and the DNS domain name (which is part of the FQDN) in the /etc/hosts file. See the warnings in section THE FQDN above, and use hostname --all-fqdns instead wherever possible โœจ
  • -F, --file filename โ€” reads the host name from the specified file. Comments (lines starting with a #) are ignored ๐Ÿ“
  • -i, --ip-address โ€” shows the network address(es) of the host name. This only works if the host name can be resolved. Avoid it and use hostname --all-ip-addresses instead ๐Ÿšซ
  • -I, --all-ip-addresses โ€” shows all network addresses of the host. It goes through every configured address on every network interface. The loopback interface and IPv6 link-local addresses are left out. Unlike -i, this doesn't depend on name resolution. Again, don't assume anything about the order of the output ๐Ÿฆ‹
  • -s, --short โ€” shows the short host name, which is the host name cut at the first dot ๐Ÿ’–
  • -V, --version โ€” prints version information on standard output and exits successfully ๐ŸŒˆ
  • -y, --yp, --nis โ€” shows the NIS domain name. If a parameter is given (or --file name), root can also set a new NIS domain ๐Ÿ‘‘
  • -h, --help โ€” prints a usage message and exits โœจ

๐Ÿ“š NOTES ๐Ÿ“š

the address families hostname tries when looking up the FQDN, aliases and network addresses of the host are decided by your resolver's configuration. For instance, on GNU Libc systems, the resolver can be told to try IPv6 lookups first with the inet6 option in /etc/resolv.conf ๐Ÿงš

๐Ÿ“ FILES ๐Ÿ“

/etc/hostname โ€” historically this file was only supposed to hold the hostname, not the full canonical FQDN. Nowadays most software can cope with a full FQDN here. The system initialization scripts read this file at boot to set the hostname ๐Ÿซถ

/etc/hosts โ€” usually this is where you set the domain name, by aliasing the host name to the FQDN ๐Ÿ’œ

๐Ÿ‘ฏ AUTHORS ๐Ÿ‘ฏ

Peter Tobias, <tobias@et-inf.fho-emden.de> Bernd Eckenfels, <net-tools@lina.inka.de> (NIS and manpage). Michael Meskes, <meskes@debian.org>


Bestie, that's the whole thing! ๐ŸŒˆ net-tools, last updated 2009-09-16, and you're officially a hostname expert now ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from