I figured out a working method. It's a bit ugly, but it does work. This leverages the ProxyCommand directive (see [manpage][1]manpage) combined with a small bash helper script.
- Add sections like this to ~/.ssh/config — one for each domain you want remapped:
Match final host="!*.corp.foo.com,*.foo.com"
ProxyCommand ssh_ext2int %h %p
Match final host="*.quux.biz"
ProxyCommand ssh_ext2int %h %p
- Save this in your
$PATHsomewhere as ssh_ext2int — andchmod u+xit:
#!/usr/bin/env bash
[ $# -eq 2 ] || exit 1
typeset -A dmap
dmap=(
[foo.com]=corp.foo.com
[quux.biz]=internal.qux.lan
)
d=${1#*.}
h=${1%%.*}
nd=${dmap[$d]:-$d}
/usr/bin/nc -w 120 $h.$nd $2 2>/dev/null
Now, ssh server158247.quux.biz should connect you to server158247.internal.qux.lan
[1]: https://man.openbsd.org/ssh_config#ProxyCommand