Linux – Is file /etc/hostname ever used for host name resolution

domain-name-systemhostnamelinux

When setting up a local Wi-Fi network in a small place from an ISP, such as Verizon, using a router and modem, the machines in the network are assigned private IP addresses.

In such a local Wi-Fi network, I can use ssh name@<hostname> to access an SSH server on another computer <hostname>, where <hostname> is the output of command hostname. Is the output of hostname resolved to a private IP address, by some DNS server (possibly on the router?)?

But I heard that the output of hostname is unrelated to host name resolution by DNS. Then why can I successfully run ssh name@<hostname>, where <hostname> is the output of command hostname?

Best Answer

There are a couple of mechanisms that could be at work here.

Firstly, a system will often include its locally-configured hostname as a DHCP Client Identifier, and the router (which is also the DHCP and DNS server) will dynamically add a DNS record for that client ID matching the IP it gave out for that request.

The other likely case is that the system is advertizing it's locally-configured hostname using Multicast DNS Service Discovery (via Bonjour services on macOS, or the avahi daemon on Linux), and many modern distros include mDNS in their NSS lookup chain by default.