How can I trick ssh to connect using different configurations based on current location?
You've sort of hinted at the solution already, and with dave4420's additional hint I sort of feel like I'm cheating by posting an answer.
Essentially, the ssh-config
ProxyCommand
directive solves the problem of "how do I connect" for the two non-local cases. The remaining question boils down to "how do I use one command and ignore the problem of figuring out which case to use."
Define a host nickname in your .ssh/config file for each of the three scenarios: Host server1a, Host server1b, Host server1c.
Define a fourth nickname which will be your command for connecting to this server, always: Host server1.
Write a script which implements the logic you've defined in your question. I can't pseudo-code this here because I'm not sure what tests you'd use to determine which of the three cases you're in. In all three cases, you have an ssh command to use, e.g.
ssh server1a
. Use this script as theProxyCommand
for the fourth nickname.
Now ssh server1
gets proxied to ssh server1[abc]
depending on context.
More on ProxyCommand
at Stupid SSH Tricks.