44

I've a small home network up and running and managed to set up ssh. Can anyone tell me what I need to do to refer to one computer on the network from another by host name rather than IP address (which is what I'm doing now)?

1

2 Answers 2

44

You can refer to machines by by tacking a .local to the hostname, like so:

ssh machinename.local

References:

3
  • I never knew that would work on non-Macs, but I just tried it on my 11.10 system, and it worked. It can probably solve a problem for me, where using the router to assign static IPs, wired and wireless on the same system have different IP addresses. Using your suggestion, I don't need to know which connection is being used. Wonder if there's a way to alias it to make it easier? Jun 14, 2012 at 2:59
  • worked perfectly, thank you. Would you mind clearing up the magic? My understanding was that a host name was only known to that particular host, unless you notified the mapping to the other hosts, like Marty said above. What does .local do? Does it initiate some sort of broadcast signal? Jun 14, 2012 at 3:03
  • 2
    I found the answer! askubuntu.com/questions/4434/what-does-local-do?rq=1 Jun 14, 2012 at 3:10
11

There are more elaborate ways, but my method is to use static IP addressed, which I can assign from my router, and enter the addresses into my hosts file.

Once you get a static address assigned, either from the router or from the Network Connections dialog (in the IPv4 tab under the Wired or Wireless tab), you edit /etc/hosts, using sudo or gksu with your preferred text editor, such as gedit or vim, and add a line for each host like so:

192.168.1.100    ComputerName1
192.168.1.101    ComputerName2

The numbers I use are common ones, but your LAN could be different. The names are whatever you want to call the remote computer, and can be anything (though probably best to match the real name). You can also create local websites by name here, if you have a local web server.

3
  • You could add the information about the names into your router to, and all machines in your local network will know these names. At least if they uses your router as DNS server.
    – Anders
    Jun 14, 2012 at 22:25
  • 1
    @Anders: How would I do that? I've never had a router that had a place to define them. My current router (Netgear WNR3500L) has a place for static IPs, and a place to name the entry, but pinging that name doesn't work for me. But it had the computer's name under "connected devices", although pinging that name also doesn't work on my system; but there must be a way to read the machine name, since the router does it. I just use hosts file, but that's not ideal. Jun 15, 2012 at 0:15
  • In the dhcp call, the computer can tell what name it want. That is why the router get the computers name. Hm, I am quite shore that I have set computer name in routers and then been able to look that name up later. I do that on my router with OpenWRT firmware now anyway. That firmware should work on your router to. Great to set up an IPv6 tunnel with. :)
    – Anders
    Jun 15, 2012 at 1:43

You must log in to answer this question.

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