Yes!
Yes, there is a way to do this directly in your ssh configuration.
host
allows PATTERNS
hostname
allows TOKENS
How:
Add this snippet to your ssh configuration ~/.ssh/config
:
# all test-* hosts should match to test-*.mydomain.example.com
host test-*
hostname %h.mydomain.example.com
Verify:
You can verify this with the -G
flag to ssh. If your ssh is older and does not support -G
you can try parsing verbose ssh output.
# if your ssh supports -G
% ssh test-17 -G | grep hostname
hostname test-17.mydomain.example.com
# if your ssh does not support -G
% ssh -v -v test-n blarg >/dev/null 2>&1 | grep resolv
debug2: resolving "test-n.mydomain.example.com" port 22
ssh: Could not resolve hostname test-n.mydomain.example.com: Name or service not known
Notes:
Ssh uses the first host line that matches. It is good practice to add your PATTERN host lines at the bottom of your configuration file.
If your test-n
name patterns contain only a single character suffix, then you can use a ?
pattern to make a less greedy match. test-?
will match test-1
test-a
test-z
but not test-10