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 root@x.x.x.x 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? 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. 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
    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
    Sep 8, 2010 at 10:25

6 Answers 6


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).
    • 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 with nss_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 with nss_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 use dhcpd + named.)

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).
  • /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.
  • 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.)
  • 9
    Haha, I like the PostIt notes option :)
    – Mr Fox
    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
    Sep 20, 2010 at 17:11
  • 1
    In Debian, you will have to install Avahi manually. 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
    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.)
    – user1686
    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
    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
    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 root@bert.local

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
    Sep 20, 2010 at 17:10
  • You've said that you can do it, but not how to do it. Jan 18 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.