When I am on a specific network (subnet 10.10.11.x), I need to jump over the intermediate host in order to reach my destination due to the destination port, which I cannot change, and the limited ports on which I can leave the limited network. I successfully use ssh configuration:
Host web-direct web HostName web.example.com Port 1111 Host web-via-jump jweb HostName web.example.com Port 1111 ForwardAgent yes ProxyCommand ssh -p 110 -q relay.example.com nc %h %p
Going through jumpers is a significant hit on performance, so I need to avoid it in most cases when it is not needed. Switching the ssh / scp / rsync host alias is good for interactive use, but there are some automated / script tasks that are very painful.
My shell remains open during network transitions, so the startup mechanisms (.zshrc) do not help.
I was thinking of running a script to poll a limited subnet and automate the switch by modifying the .ssh / config file, but I'm not even sure that there will be a problem with caching. Before implementing this, I thought to ask if there is a better approach.
What is the best approach to replace ssh configuration based on discovering the source host subnet?
In the pseudo-config, something like:
if <any-active-local-interface> is on 10.10.11.x: Host web HostName web.example.com Port 1111 ForwardAgent yes ProxyCommand ssh -p 110 -q relay.example.com nc %h %p else: Host web HostName web.example.com Port 1111 endif
source share