2

This question is meant to be specific to a home network.

Windows, Linux, and MacOS computers all have a host name. In addition, MacOS computers have a computer name and a local host name. And when a device is connected to a home network, a DHCP entry is created with possibly a different name.

All of these names may be different and I have not found much of a use for most of them. On MacOS, aside from querying from the command line, there seems to be little or no use for the computer name. The local host name is apparently used by Bonjour to identify the computer. By default, the host name is not set. If set, the hostname command returns that name, but if not set, then the local host name is returned.

On Linux, the host name seems to be of little use other than identifying the computer by executing the hostname command. On Windows, there is a value returned by hostname but I have not found any other use for it. Maybe something in a Wins server?

I am not sure where DHCP gets the names it uses. For my MacOS computer, it does not use any of computer name, local host name, or host name. For my Linux computer, the DHCP name is the same as the computer's host name; is that by chance, or does Linux provide that name? I changed the host name on the Linux computer and then restarted it, but the DHCP name did not change.

I can only map a computer or host name to a static IP address by adding an entry in the /etc/hosts file, so in general, all of these names seem to be of little use.

So, what are all of these names really used for?

2
  • The DHCP server might optionally include a host name with its answer to the client computer.
    – harrymc
    Commented Oct 22, 2023 at 17:05
  • 1
    I changed the host name on the Linux computer and then restarted it, but the DHCP name did not change ... try rebooting the router
    – jsotola
    Commented Oct 22, 2023 at 17:28

2 Answers 2

4

On Linux, the host name seems to be of little use other than identifying the computer by executing the hostname command. On Windows, there is a value returned by hostname but I have not found any other use for it. Maybe something in a Wins server?

It used to go to WINS, yes – and similarly, NetBIOS local name discovery in places that didn't have a WINS server, so that you could ping Jimputer to reach your computer over your home network. It's exactly like Bonjour in macOS.

In fact, both Windows and Linux also use the hostname for actually the same Bonjour as on macOS – under the name of Avahi on Linux, or the generic mDNS more broadly. These days, WINS and NetBIOS NBNS are no longer a thing – if you try to access a local hostname in Windows, it'll be resolved via Bonjour first.

But note that Bonjour/mDNS is two things: it does hostname lookup, but it also does service discovery. The former is what uses the short 'hostname', but the latter – meant to show your computer in the "Network" list – uses the long 'computer name', which may include any special characters because it's not meant to be typed-in anywhere.

This "service discovery" part of Bonjour is explicitly meant to mimic how networking worked in AppleTalk (Mac OS Classic), where hostnames as such didn't exist (nor did SSH or Ping or terminals). Network printing, file-server access, everything worked via free-form service names that you selected from a list, and therefore "computer name" was a Mac's primary identity in an AppleTalk network. Hostnames only came to Macs with TCP/IP and with the Unix-based OSX.

I am not sure where DHCP gets the names it uses. For my MacOS computer, it does not use any of computer name, local host name, or host name. For my Linux computer, the DHCP name is the same as the computer's host name; is that by chance, or does Linux provide that name?

It is normally provided from the system hostname, yes. Windows always does so; on Linux it depends on which of the 100 different DHCP clients you use, but generally the system hostname is used by default.

While in small LANs the hostname usually reaches local DNS via DHCP, that's not the only method – in larger networks with Active Directory, Windows also sends a DNS 'UPDATE' for its system hostname directly to the AD DNS server.

By default, the host name is not set. If set, the hostname command returns that name, but if not set, then the local host name is returned.

Note also that macOS, by default, will also take the hostname from DHCP, if the lease provides one. (You often see people here confused about why they have [email protected] as their shell prompt.) So now you also have two parameters: one is the permanent, manually-configured hostname (in /etc/hostname on Linux), the other is the temporary, currently-active hostname (in the hostname command on Linux).

And that's how you have three in total:

macOS Linux (hostnamectl) Usage
"Hostname" "Transient hostname" The actual currently active system hostname (either initialized from static hostname, or overridden from DHCP). This is what's retrieved by various programs and services when they call 'gethostname()'.
"Local hostname" "Static hostname" Manually set hostname that's used as the system hostname if nothing overrides it. Not directly used by apps.
"Computer name" "Pretty hostname" Free-form "display name" to be shown in network discovery lists (Bonjour/Avahi); generally not used by much else.

Finally, the same system hostname is also what's typically used by various third-party features because of how easily it's accessible to programs (traditionally there's a very simple API call to retrieve it). For example, it acts as a default device label in Dropbox or Syncthing or Steam or Spotify; even if the OS doesn't necessarily use it much, other software find plenty of uses.

6
  • Thank you. The info you provided was enough to send me down a couple of rabbit holes looking for more info. avahi on Linux only works when the appropriate port is opened in the Linux firewall. avahi-browse shows my Mac's computer name, but to connect to it, I must use the local host name. Bonjour on Windows finds both my Mac and openSUSE computers and I can ssh into them. Still having problems with resolution on MacOS, but I will continue chasing rabbits down holes. Commented Oct 24, 2023 at 12:29
  • @JimOrcheson: The service names in avahi-browse aren't meant to work directly with SSH anyway; everything that is "browseable" is non-'host' entries that only point to some host name that provides them. There is no method in Bonjour/Avahi to just directly browse hosts by their hostname. (If you use --resolve, or if you click on one of the items in avahi-discover, the bottom view will show which address:port it points to. Something similar can be done on macOS using the dnssd tool.) Commented Oct 24, 2023 at 13:15
  • The "service" part of Bonjour is meant to mimic how service discovery worked in AppleTalk (Mac OS Classic), where hostnames as such didn't exist (nor did SSH or Ping or terminals) – stuff like network printing, fileserver access, everything worked via free-form "service names" that you selected from a list, and therefore "computer name" was a Mac's primary identity. Hostnames came later, with TCP/IP. Commented Oct 24, 2023 at 13:19
  • @JimOrcheson: As for SSH, though, Avahi has a wrapper bssh that lets you choose out of hosts that advertise the "SSH" service (used to be default, not anymore) and to run ssh for it. GNOME's Nautilus or Thunar will similarly discover "SFTP" servers. Commented Oct 24, 2023 at 13:22
  • Thanks for the additional info. I have been able to access the web server on my openSUSE computer without having an entry in /etc/hosts by using jimpc.local, and also to access ssh using ssh [email protected], so I guess everything is working as it should. Commented Oct 24, 2023 at 15:39
0

The short answer is, it's a mess of legacy baggage from a long history of incompatible name resolution and service discovery protocols with different rules like allowed character sets and length limits.

So a host's name can be different depending on which protocol you use to ask the question.

It has never converged on a single widely compatible system and probably never will. OSes each have a different strategy for taming this mess—like trying to generate one name based on another, or letting you customize each one separately—which just makes more complexity when working cross-platform.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .