Is it possible to connect to a device using its hostname?
I am creating a small device running Linux with a web server on it. I want it to be plug and play, connect to a network and access to it using an abstract name.
Is it possible to access to a device using only its hostname?
On some networks – yes. But on your everyday TCP/IP network, the hostname must be translatable to an IP address, otherwise clients will not know what to connect to.
There are several existing protocols for local name lookup, though:
-
Windows traditionally used to use NetBIOS name services for resolving hostnames of other computers in the same LAN, using UDP broadcasts. Your server will need to run the
nmbd
component of Samba to be discoverable using NetBIOS.Recent Windows versions also support LLMNR, which is similar to mDNS but has fewer features and requires IPv6. On Linux,
systemd-resolved
will have a LLMNR client. No idea about other operating systems. Probably not worth considering.The latest releases of Windows 10 also support mDNS.
-
OS X uses mDNS ("multicast DNS"), sometimes known as Bonjour, for the same purposes. (Note that mDNS generally does not resolve bare hostnames like NetBIOS would; instead, it is limited to the
.local
domain.) For mDNS, your server will needavahi-daemon
.Newer Windows 10.19xx have mDNS support built in (but disabled). Older Windows can resolve mDNS names if Bonjour is installed (typically as part of iTunes), and OS X should support NetBIOS if "Windows file sharing" or a similar service is enabled.
Desktop-oriented Linux systems often come with both NetBIOS and mDNS resolvers preconfigured. (That is, they run both
nmbd
andavahi-daemon
, plus the relevant glibc NSS modules in/etc/nsswitch.conf
.)Finally, most "home routers" maintain a local DNS domain (
.lan
,.home
, &c.) according to hostnames they receive from DHCP requests sent by computers in the LAN. Depending on what your server uses,dhcpcd
needs the "hostname
" option, whiledhclient
uses "send host-name = gethostname()
".