Connect to Linux by name rather than IP
Solution 1:
Zero-configuration LAN discovery protocols, in order of preference:
-
mDNS
- Used primarily by Apple products and some Linux programs, but also available for Windows and possibly other platforms; uses IP multicast.
- Provides both name lookup and service discovery.
- Host names are always in the form
name.local
. - Software:
- natively supported on Windows 10.1709 and later (must be enabled via Registry);
- Bonjour on older Windows;
-
Avahi with
nss_mdns
on Linux; - natively supported on OS X and iOS (and, supposedly, Android).
-
LLMNR
- Used for name resolution by Windows Vista and above, as a modern alternative to NetBIOS name services.
- Very similar to mDNS, but has fewer features – in particular, lacks service discovery (Windows uses the WS-Discovery protocol for that).
- Uses bare hostnames (like NBNS, but unlike mDNS).
- Software:
- Natively supported by Windows Vista and later;
-
systemd-resolved
withnss_resolve
(part of systemd 216) on Linux. .
-
NetBIOS name services
- Part of the old NetBIOS network protocol suite used by Windows, OS/2, MS-DOS... Still in use. Not an excuse to start using it on new networks.
- Provides name resolution and (to some extent) service discovery – aka "Network Neighbourhood" or "My Network Places" in Windows.
- Uses IPv4 broadcasts (somewhat chatty), and has its own complex and stupid "browser election" protocol to reduce the chattiness. No IPv6 support at all.
- Software:
- Natively supported on Windows and OS/2;
-
nmbd
withnss_wins
(part of Samba) on Linux and BSD's; - Apparently OS X supports it natively as well?
Methods that are often pre-configured for you:
-
DNS using a local (internal) domain name
- Home gateways tend to have this built-in, as part of the local DNS cache. Often it's just regular
dnsmasq
, which you could run manually if you're setting up a Linux/BSD-based gateway. - They take the hostname from your DHCP request, register it within dnsmasq under a domain like
home
, and offer themselves as the main DNS server (act as DNS cache). - Works by default with most operating systems, but only with DHCP (the gateway doesn't know hostnames of static-IP hosts), and generally tends to be rather flaky in my experience.
- Software:
- A regular DHCP client on the hosts. Must send the hostname option.
-
dnsmasq
on the gateway. (Larger setups could usedhcpd
+named
.)
- Home gateways tend to have this built-in, as part of the local DNS cache. Often it's just regular
Methods involving manual configuration:
-
DNS using your own domain name
- Works everywhere. (Won't help you to actually connect over the Internet, though.)
- Dynamic DNS possible if you use DHCP and control a DNS server; otherwise all data is static.
- Need to own a domain name (which will cost a few bucks).
-
free DNS subdomains
- Still DNS, just free (or much cheaper than a domain), but also quite limited. Services like FreeDNS and Dyn offer registration of individual subdomains under a domain they control (for example
myhost.dyndns.com
).- Way too often, the subdomain has already been picked by someone else...
- Dynamic DNS updates are often allowed (DynDNS-style).
- Still DNS, just free (or much cheaper than a domain), but also quite limited. Services like FreeDNS and Dyn offer registration of individual subdomains under a domain they control (for example
-
/etc/hosts
- A text file listing IP address – hostname pairs, which must be manually configured on each client machine.
- (
%SystemRoot%\system32\drivers\etc\hosts
on Windows)
-
SSH configuration
- The "Hostname" field in PuTTY, or
~/.ssh/config
on OpenSSH. - Must be manually configured.
- The "Hostname" field in PuTTY, or
-
PostIt notes all over your desk
- Very cheap. No naming policy. Infinite data types.
- Rather unreliable. Must be manually distributed. No TTL, which often results in stale information being cached for months until someone notices. Query algorithms are inefficient. Responses to queries tend to get lost easily, sometimes leaving just a glue record on your monitor. (Three months later, you might find them buffered behind your desk.)
Solution 2:
Two options.
- All services:
Put an entry for it in /etc/hosts
. Don't touch existing lines, add a new one.
- ssh only:
Add a Host
stanza to ~/.ssh/config
with the name you want to use, then add desired options below that. See man 5 ssh_config
for more details.
Host myserver
Hostname 192.168.123.234
Protocol 2
Solution 3:
If you want to access the Linux box from an arbitrary computer, you would need a domain name. Use a dynamic DNS service to point a domain name to your Linux computer (or the router it is connected to). Once you set this up, it will give yo the additional benefit of not having to worry about the IP of your Linux computer ever changing.
Solution 4:
From Windows 7 (per your edit)...
Start -> Run -> notepad c:\windows\system32\drivers\etc\hosts
When notepad starts, go to the bottom of the file and add your ip address and hostname:
x.x.x.x mylinuxhostname mylinuxhostname.domain.com
Save the file, then try pinging it from a command prompt:
c:\> ping mylinuxhostname
c:\> ping mylinuxhostname.domain.com
This will only work from your LAN. Connecting to it from "the world" (per your comment added) is an entirely different beast involving a DNS (dyndns, godaddy, etc) and router configuration like (NAT) network address translation et al.
Solution 5:
You're going to want to investigate Samba or Winbind. My all-Linux network (including the router) can talk to each other by hostname, but I'm not sure how to tell Windows what a Linux machine's name is.