ssh_config: Hostname with multiple IP addresses

Bob Proulx bob at proulx.com
Tue Dec 15 10:57:03 AEDT 2020


David Newall wrote:
> All of this fails to help the original question, which is how to specify
> multiple IP addresses.  The obvious answer to that is to put multiple A
> records into your local DNS.  If you don't have a local DNS or have no
> control over it, specify multiple Hosts in your config, one for each IP
> address.

Just some brainstorming here...

It should always be possible to populate the local /etc/hosts file as
an override to DNS with a local unique name.  And then use that local
name in the config file.

Example /etc/hosts:

    93.184.216.34 foo.example.com foo
    2606:2800:220:1:248:1893:25c8:1946 foo.example.com foo

Example ssh config:

    Host shortname realname.example.com
      HostKeyAlias realname.example.com
      Hostname foo

Use like:

    ssh shortname
    ssh realname.example.com

I tested this just now and on a host with IPv6 connectivity it used
the IPv6 address.  The same configuration on a host with only IPv4
connectivity used the IPv4 address.

It's perhaps not the simplest of configurations but it did seem to fit
the criteria.  The way to get both an IPv4 and an IPv6 address
available to Hostname.  By stitching it through the /etc/hosts file.
WDYT?

Bob



More information about the openssh-unix-dev mailing list