Results 1 to 10 of 10

Thread: Cannot SSH using hostname

  1. #1
    Join Date
    Oct 2017
    Beans
    16

    Cannot SSH using hostname

    Hello.

    I cannot SSH into machine using machine's hostname, but I can with IP address.

    This is the output of nslookup hostname:

    Code:
    Server:        192.168.1.1
    Address:    192.168.1.1#53
    
    Name:    hostname
    Address: 192.168.1.5
    Name:    hostname
    Address: 192.168.1.5
    ping hostname:

    Code:
    ping: hostname: Name or service not known
    And my resolv.conf:

    Code:
    # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
    #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
    # 127.0.0.53 is the systemd-resolved stub resolver.
    # run "systemd-resolve --status" to see details about the actual nameservers.
    
    nameserver 192.168.1.1
    nameserver fe80::1
    nameserver 127.0.0.53

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

    Re: Cannot SSH using hostname

    If you can't ping by the name you want, then you haven't setup your network name resolution correctly. It isn't automatic.

    There are 3 popular solutions.
    1) modify the /etc/hosts on all the systems you want to know the IP -to- name mapping. This is what I use on my subnet. I use ansible to push updates for the hosts file out to all the systems here. We use ansible for many other solutions too.
    2) use a DNS server, which you manually maintain on the network. Some routers can do this, but most require complex manual setups.
    3) use avahi on all systems. This means using {hostname}.local as the name to ping/ssh/access.

    IP networking doesn't include any automatic announcement that "I'm here, I'm here" like some other network protocols (smb/cifs) from other OSes do. Those broadcasts don't really scale beyond a tiny network and aren't part of the IP standards.

    Welcome to the forums.

  3. #3
    Join Date
    Oct 2017
    Beans
    16

    Re: Cannot SSH using hostname

    Quote Originally Posted by TheFu View Post
    If you can't ping by the name you want, then you haven't setup your network name resolution correctly. It isn't automatic.

    There are 3 popular solutions.
    1) modify the /etc/hosts on all the systems you want to know the IP -to- name mapping. This is what I use on my subnet. I use ansible to push updates for the hosts file out to all the systems here. We use ansible for many other solutions too.
    2) use a DNS server, which you manually maintain on the network. Some routers can do this, but most require complex manual setups.
    3) use avahi on all systems. This means using {hostname}.local as the name to ping/ssh/access.

    IP networking doesn't include any automatic announcement that "I'm here, I'm here" like some other network protocols (smb/cifs) from other OSes do. Those broadcasts don't really scale beyond a tiny network and aren't part of the IP standards.

    Welcome to the forums.
    But the other PC (the one I am trying to SSH into) can SSH into this one with hostname, and can ping this one using hostname too. Both of them are on the same router. So (I think) I already have DNS server.

  4. #4
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: Cannot SSH using hostname

    You're sure that 192.168.1.5 is the correct address for that host?

    What if you add the entry

    Code:
    192.168.1.5     hostname
    to /etc/hosts. (Use "sudo nano /etc/hosts" to edit the file if you've not modified system files like this before.) Now try to connect with ping and ssh. Any better? If not, I'd check the target's IP address again.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  5. #5
    Join Date
    Oct 2017
    Beans
    16

    Re: Cannot SSH using hostname

    Quote Originally Posted by SeijiSensei View Post
    You're sure that 192.168.1.5 is the correct address for that host?

    What if you add the entry

    Code:
    192.168.1.5     hostname
    to /etc/hosts. (Use "sudo nano /etc/hosts" to edit the file if you've not modified system files like this before.) Now try to connect with ping and ssh. Any better? If not, I'd check the target's IP address again.
    192.168.1.5 is correct. After all, I can SSH into the machine with that IP.
    Adding
    Code:
    192.168.1.5    hostname
    to /etc/hosts does work, but I don't want to use that since IP changes sometimes (I use DHCP) so I have to change entry in /etc/hosts manually every time address changes. I know I don't need
    Code:
    192.168.1.5    hostname
    in /etc/hosts because the other machine also doesn't have that entry for this machine but it always connects succesfully to this machine even when IP of this machine changes, only using hostname.
    Last edited by stii; February 17th, 2018 at 03:17 PM.

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

    Re: Cannot SSH using hostname

    Setup dhcp reservations on your network so that machines always get the same IP.
    http://blog.jdpfu.com/2011/07/18/use...ice-management

    Troubleshooting ssh: http://blog.jdpfu.com/2015/08/17/tro...sh-connections
    * check the logs and
    * up the debug "verbosity"
    is basically what it says.

  7. #7
    Join Date
    Oct 2017
    Beans
    16

    Re: Cannot SSH using hostname

    I solved it. Here is where I found the solution: https://askubuntu.com/a/81807

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

    Re: Cannot SSH using hostname

    Quote Originally Posted by stii View Post
    I solved it. Here is where I found the solution: https://askubuntu.com/a/81807
    Happy that you found a solution - it would be helpful if you summarized which of the choices worked.

    The more the "new kids" try to make things better, the more often they mess up the 40 yr old stuff that has been working all this time, just without as much automation. mdns is one of those things. resolvconf is another. Good intentions on both, but they don't handle all the old-school methods which are commonly deployed well at all.

    IMHO.

  9. #9
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: Cannot SSH using hostname

    Quote Originally Posted by stii View Post
    I solved it. Here is where I found the solution: https://askubuntu.com/a/81807
    I have no .local or any similar domain. I use the .com and .org domains that I control. Never would have guessed the problem lay where it did. Hosts do not need to belong to a domain, so the command "ssh hostname" is perfectly valid and need not be munged to "ssh hostname.local". I'm with TheFu on these kinds of "innovations."
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  10. #10
    Join Date
    Oct 2017
    Beans
    16

    Re: Cannot SSH using hostname

    The link leads to the first chosen answer.

Tags for this Thread

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
  •