I'm new to Linux (currently running Ubuntu 10.04) and I have just finished setting up SSH access to my Linux Machine. Currently, I have to use ssh [email protected] to connect but would much rather be able to swap the IP for the computer name (like in Windows with \\name) or a domain name (like computername.example.com).

I don't really know where to start so any help would be most appreciated. Please go slowly, as mentioned - I am still new to this.


Completely forgot to mention that I am trying to connect from Windows 7 (via PuTTY) - sorry.

  • Are you trying to connect just from within your LAN or from anywhere in the world? Commented Sep 7, 2010 at 16:11
  • 7
    Also, FYI allowing connections via ssh as root is generally considered a bad idea security-wise. It's recommended to log in as a regular user and use su or sudo from there. Commented Sep 7, 2010 at 16:14
  • Both my LAN and the world (though I think I know how to set up the world access so this question is more for LAN) - and the root@ was more example than anything - I do actually use a user.
    – Mr Fox
    Commented Sep 7, 2010 at 16:17
  • Loads of great answers - thanks to everyone - though I had to pick one so I picked the most detailed.
    – Mr Fox
    Commented Sep 8, 2010 at 10:25

6 Answers 6


1. Zero-config protocols (in order of preference)

1.1. mDNS (Multicast DNS)

mDNS originates from Apple and is also known by the name Bonjour, which is Apple's branding for their mDNS implementation. It was originally an IP-based replacement for AppleTalk discovery services.

These days mDNS is available on most platforms and is generally the preferred choice, both for hostname lookup and for service discovery (where it's simpler than many alternatives).

mDNS hostnames are always in the form name.local. (Exception: The built-in mDNS handling in Windows 10+ will accept bare hostnames like it has done previously, automatically translating them to the mDNS format behind the scenes.)


  • Natively supported on Windows 10.1709 and later. (At first it was opt-in through a Registry setting, but I believe it's on-by-default now, at least in Windows 11.)
  • Can be installed as Apple's Bonjour on Windows XP.
  • Avahi with nss_mdns is still the preferred option for Linux and BSDs.
  • systemd-resolved with nss_resolve is another option for Linux (newer than Avahi but still incomplete).
  • Natively supported by macOS (OS X) and iOS.
  • Natively supported by Android _(I know Android 11 recognizes .local domains, but from what I remember, Android 7 did not yet).
  • Natively supported by my Bosch washing machine, apparently.
1.2. LLMNR

LLMNR was introduced with Windows Vista as a modern alternative to NetBIOS Name Services (NBNS), being a very similar protocol to mDNS (but using bare hostnames, and lacking the service discovery features – Vista uses the WS-Discovery protocol for that purpose instead).

However, as of 2023, considered a dead-end – Microsoft eventually gave up and fully pivoted to mDNS for local name resolution.

  • Natively supported by Windows Vista – Windows 11.
  • systemd-resolved with nss_resolve (part of systemd 216) on Linux. .
1.3. NBNS (NetBIOS Name Services)

Part of the old NetBIOS network protocol suite used by Windows, OS/2, MS-DOS, etc. Anything that speaks SMBv1 is likely to support NBNS. (And likewise, it's as obsolete as SMBv1 is, and if you disable SMBv1 support in Windows, this also disables NBNS.)

Provides name resolution and (to some extent) service discovery – NBNS was part of what originally powered "Network Neighbourhood" or "My Network Places" in Windows.

NBNS has no IPv6 support whatsoever. It's also prone to breaking due to some underlying complexity (the "Browser Election" mechanism that was originally meant to reduce the chattiness).

  • Natively supported on Windows and OS/2.
  • nmbd with nss_wins (part of Samba) on Linux and BSDs.
  • Apparently OS X supports it natively as well?

2. Methods that are often pre-configured for you

2.1. 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.

Your gateway takes the hostname from your DHCP request, registers it within its internal DNS service under a domain like .home or .lan, and offers itself as the main DNS server (acting as DNS cache).

Works by default with most operating systems, but only with DHCP (the gateway doesn't know hostnames of manually-configured hosts), and generally tends to be rather flaky in my experience.


  • A regular DHCP client on the hosts. Must send the 'hostname' option in its lease requests (most devices do).

  • dnsmasq on the gateway. (Larger setups could use dhcpd + named.)

3. Methods involving manual configuration

3.1. 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.

You need to actually own a domain name (which will cost a few bucks).

3.2. 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).

3.3. /etc/hosts

A text file listing IP address – hostname pairs, which must be manually configured on each client machine.

The location is %SystemRoot%\system32\drivers\etc\hosts on Windows, /etc/hosts on Linux and others.

3.4. SSH client configuration

You can save pre-filled hostnames in PuTTY connection profiles, and you can similarly define short names through ~/.ssh/config in OpenSSH.

3.5. PostIt notes all over your desk

Pros: Very cheap. No naming policy. Infinite data types.

Cons: 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.)

  • 11
    Haha, I like the PostIt notes option :)
    – Mr Fox
    Commented Sep 8, 2010 at 8:07
  • 1
    +1 for mDNS / Avahi. Avahi is installed by default on many distros, but may be a package install for yours.
    – Broam
    Commented Sep 20, 2010 at 17:11
  • 1
    In Debian, you will have to install Avahi manually. Commented Jun 27, 2013 at 15:14
  • 2
    @grawity Good answer. One thing to improve though: Have in mind that local DNS/DHCP works perfectly fine without a registered domain. Just throw a Raspberry PI under your desk and setup a small server with e.g dnsmasq.
    – gilgwath
    Commented Aug 20, 2014 at 12:50
  • 1
    @paradoxon: Thanks, I forgot to mention that. (Most home gateways do already run dnsmasq or something similar but crappier.) Commented Aug 21, 2014 at 5:53

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
    Protocol 2

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.

  • 1
    Just to clarify, the IP address of the computer may still change (depending on how your ISP manages that stuff), but you won't have to worry about it since the dynamic DNS service provides a domain name that always maps to whatever the current IP address of the computer is.
    – David Z
    Commented Sep 7, 2010 at 17:31

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.


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.

  • 1
    My network does this because of Avahi (Zeroconf networking). I do not know the viability of a Zeroconf client/server on Windows.
    – Broam
    Commented Sep 20, 2010 at 17:10

I'm also using Ubuntu 10.04 and I can connect to my machines by appending .local to their name.

Say I have computers named ernie and bert that are on the same network. My prompt looks like this on ernie:


If I type this:

ernie:~$ ssh [email protected]

I'll be root on bert:


I do this between two ubuntu machines, but I'd guess it would work in putty too. (I don't know about connecting to Windows from Ubuntu, see other answers about samba.)

You have to install sshd in Ubuntu for this to work: sudo apt-get install openssh-server

  • 2
    This is because of Avahi, a Zeroconf daemon that is installed by default. It's not going to help him on Windows, unless he has a client due to some other reason (maybe iTunes installs one? I can't say.)
    – Broam
    Commented Sep 20, 2010 at 17:10
  • You've said that you can do it, but not how to do it. Commented Jan 18, 2023 at 4:11

You must log in to answer this question.

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