Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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)?

share|improve this question
add comment

2 Answers

up vote 11 down vote accepted

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

ssh machinename.local

References:

share|improve this answer
    
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? –  Marty Fried Jun 14 '12 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? –  naftalimich Jun 14 '12 at 3:03
    
I found the answer! askubuntu.com/questions/4434/what-does-local-do?rq=1 –  naftalimich Jun 14 '12 at 3:10
add comment

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.

share|improve this answer
    
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 '12 at 22:25
    
@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. –  Marty Fried Jun 15 '12 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 '12 at 1:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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