I have a system with both a public (e.g server1.foo.bar) and privately-resolvable (e.g. server1.internal.foo.bar) DNS name. SSH connections are only possible via the private IP, but I always think of these hosts in terms of their public name.
I would like to:
- connect to the right IP regardless of whether I remember to use the
*.internal.bar
pattern - save keystrokes
I'm aware of the substitution tokens such as %h
that can be used to modify the hostname given at the commandline, e.g.
Host foo
Hostname %h.some.other.domain
The behavior I'm looking for would be something like:
Host *.foo.bar
Hostname %m.internal.foo.bar
Where %m
gets substituted with just the portion of the given hostname up to the first dot. I've read man 5 ssh_config
as well as https://man.openbsd.org/ssh_config and couldn't find the answer, if one even exists. I'm using macOS 10.15.4:
$ ssh -V
OpenSSH_8.1p1, LibreSSL 2.7.3
server1.foo.bar
to your/etc/hosts
with the address ofserver1.internal.foo.bar
? Then the name will also work outside of ssh (ping, http, git...).Hostname
thing in the SHH config works for single hosts, so I assume you have many servers? This is something I would solve with a small script or a loop that generates aliases. Or you just define 'serverX` in your/etc/hosts
and usessh serverX
. On my Linux I get bash command completion ofssh
with host names that are in/etc/hosts
so in practice you would just enter the ends of the names.