HowTo use SSH with a Short Hostname

Version 2

    This post is basic and aimed for IT managers and lab users.

     

    The Problem

     

    In many cases the full domain is required to be added to the hostname when using SSH, otherwise the SSH/DNS will not be able to resolve/translate the name to IP address.

    For example, in case I have a server called Server01 in a domain called mydomain.com, trying to ssh to the hostname only will not resolve.

     

    # ssh admin@Server01

    ssh: Server01: Name or service not known

     

    The Solution

     

    To resolve this, create/edit a file called ~.ssh/config, under ~.ssh/ folder, and add the following lines to it.

    Host server01

    HostName server01.mydomain.com

     

    Host switch02

    HostName switch02.mydomain.com

     

    Once doing that, the SSH will replace the host with the hostname plus the full domain.