Ubuntu: Cannot ssh into Ubuntu Server by hostname



Question:

I just set up Ubuntu 12.04 Server on an old box laying around, connected to my router via ethernet. I set up openssh-server as instructed for remote access, but I cannot ssh into it from my laptop using the hostname.

Strangely though, I can ssh into it using the IP address. I would really like to fix this for the sake of convenience. I notice there are a few similar questions, but it seems all these people had some idea of what direction to go in to fix the problem, and were asking slightly more specific, technically-worded versions of my questions.

As a complete beginner to home networking, I would majorly appreciate if someone would tell me where to go from here.


Solution:1

Unless you configure hostnames in a central location, there's no way for your laptop to know the hostname you configured on the Ubuntu server.

So if when you installed the ubuntu server you named it "bonkers", it's understandable that on the laptop ssh bonkers will not do anything, as the laptop has no idea about that hostname.

Possible solutions:

  • On your laptop (you didn't say which OS it is running?) add a line in the /etc/hosts file for your Ubuntu server's IP address, something like this (use the actual IP from your Ubuntu server):

    10.15.30.41 ubuntu-server

    Then you can do ssh ubuntu-server and it should work. Note that the location of the hosts file depends on which OS your laptop has; I'm not sure where it is on Windows, for example.

  • Install the avahi-daemon package on your Ubuntu server. This utilizes the mDNS protocol to "advertise" its hostname on your local network. Once it's installed and running, you should be able to ssh ubuntu-server.local (notice the .local domain) and access the server. Again, if your laptop is running Windows, I can't say if it supports mDNS; I know Ubuntu (and any other Linux with avahi-daemon installed) and Mac OS X support it out of the box.


Solution:2

I had a similar problem and tried to solve it installing Avahi-daemon, just as roadmr suggested, but with apparently no result. Then I typed

host myhostname  

and the terminal answered me:

myhostname.lan has address 192.168.1.68  Host myhostname.lan not found: 3(NXDOMAIN)  

In the guest machine Iused as hostname myhostname.lan and it just worked. Until I am connected with DHCP. With assigned IP it does not work...


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »