How to automatically switch ssh config based on local subnet?
You can use Match
's exec
option to execute shell commands, so you can write something like this:
Match host web exec "hostname -I | grep -qF 10.10.11."
ForwardAgent yes
ProxyCommand ssh -p 110 -q relay.example.com nc %h %p
Host web
HostName web.example.com
Port 1111
The Match
option boolean logic can short-circuit, so put host
first to skip the exec
term for other hosts. Try ssh web -vvv
to see the Match
logic in action.