Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Why can't I ssh by name?

  1. #1
    Join Date
    Jul 2006
    Beans
    261

    Why can't I ssh by name?

    Hello, I am not sure if this is an ubuntu issue or an issue with my router. I have a fresh install of ubuntu. I gave this the hostname of "mypc". When I ssh from another PC, if I do "ssh sim085@192.168.1.111" it works fine. However if I do "ssh sim085@mypc" it tells me "Could not resolve hostname mypc Name or service not known". When on mypc I check /etc/hostname and this is set to "mypc". When I check the router I can see that mypc is listed. So what might be the issue?

  2. #2
    Join Date
    Jul 2006
    Beans
    261

    Re: Why can't I ssh by name?

    Just to say that this happens only when I try to ssh from another linux machine. When I ssh from a Windows machine (through putty) I do manage to connect to the machines by the machine name. So the issue seems to be with the linux machine I am using to ssh to the other machine.

  3. #3
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Why can't I ssh by name?

    For that to work with only the computer name, you would need to add an entry to the /etc/hosts file on the computer you're sshing from

    Code:
    192.168.1.111         mypc
    However, you should be able to use

    Code:
    ssh sim085@mypc.local
    which uses the avahi discovery service to resolve names on the local network

  4. #4
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Why can't I ssh by name?

    @Steeldriver - great post. However, I see mixed results with .local lookups here. Tried 3 different pings for 3 different machines on the local network "hostname.local"
    * 1 is correct - worked as hoped.
    * 1 is on an incorrect subnet (vnet* device address returned)
    * 1 does not answer. failed.

    This could be an issue with my network, since we have DNS and /etc/hosts setup for almost all the machines already.

    Another workaround is to create a ~/.ssh/config file. Then an alias for the hostname can be added, but the IP address can be put in for address resolution.
    Code:
    host regulus
     Ciphers arcfour
     user rooter
     hostname 172.22.22.44
     port 64022
    Multiple stanzas like that can be used. The manpage is pretty good ssh_config is the name. All tools which are built on ssh will support these settings. ssh, sftp, scp, rsync, rdiff-backup, etc.... userid, ports, cyphers are added to those commands automatically. No more need to remember if a cmd required -p or -P to specify a port or what userid is setup on the other host!

    Anyway - just another option to use with ssh.

  5. #5
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Why can't I ssh by name?

    Good point @TheFu! I completely forgot about the ~/.ssh.config, that would be the obvious choice in this case

    Note to self: don't post before coffee

  6. #6
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Why can't I ssh by name?

    About 4 months ago, I showed a Unix guy with 30 yrs experience the ~/.ssh/config file - he'd never heard of it. This is a professional RHEL admin. Just one more example of how flexible Linux is and how **nobody** can know it all. BTW - the file name/path here is correct.

    Don't know if this is the best choice, but whenever I need a non-default ssh-based connection to any other system, putting settings into my config file is the first thing I do.

    I see it as more than just a way to control options - it is also a handy-to-have document as a reminder. For example, I manage some networks in Nepal, but don't have to do much there very often. Clearly, I've been trying to see how the networks AND my friends there are doing. Haven't been able to login and haven't seen any other communication from my friends yet. They have a generator, but I suspect fuel ran out and their fibre link probably hasn't worked all week.

  7. #7
    Join Date
    Jul 2006
    Beans
    261

    Re: Why can't I ssh by name?

    Thanks to both for the replies. I tried "sim085@mypc.local" but this did not work out for me. Got the same error message. I would like to avoid having to write the IP Address in a file to get a connection with the name. The reason is that at the moment the router provides a different IP to the machine each time this is turned off / on. I would need to maintain these files if I write the IP. That is why I originally wanted to access the machine through the name not IP. I could use static IP's but I am trying to avoid that at the moment.

  8. #8
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Why can't I ssh by name?

    What you want is a combination of DHCP reservations and DNS.
    http://blog.jdpfu.com/2011/07/18/use...ice-management

    If you don't have static IPs, Unix services will move around. That is the way IPv4 works. Sorry.

  9. #9
    Join Date
    Jul 2006
    Beans
    261

    Re: Why can't I ssh by name?

    I could use static IPs; However I wonder why it works from putty but not from linux terminal? The routers knows that "mypc" ip address is xxx.xxx.xxx.xxx so shouldn't the linux machine I am using to connect to mypc be able to resolve the IP Address of mypc with the router?

  10. #10
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Why can't I ssh by name?

    Exactly how does the router have this information? Is it running DNS? There are standard protocols for name resolution under every OS. Linux supports those standards. Non-standard extensions many or may not be supported and I don't have any idea why Windows works or doesn't work. Sorry.

    I know that /etc/nsswitch.conf specifies the order and protocols used by Linux to resolve hostnames to IP addresses. For a small network, /etc/hosts and DNS are normally used for Linux/Unix hostname resolution by other hosts on the network. In the old days, we might use NIS (also called yp) too, but that wasn't secure for all that is did - groups, userids, passwords, hosts, netgroups, .... and Windows didn't support NIS. NIS+ has replaced NIS, but Sun (now Oracle) didn't release or license the server code to other vendors. There are NIS+ clients for every Unixen, but only Solaris has the NIS+ server code. Sorry - off topic.

    So, if you want this to work ...
    * setup DHCP reservations and DNS on your router
    OR
    * manage /etc/hosts files across all the boxes. Ansible is the tool I use for this.

    I've made lots of assumptions here - like the network is relatively small (20 or less devices). If the network is larger, there are better ways, IMHO.
    Last edited by TheFu; April 30th, 2015 at 12:51 PM.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •