When I\'m on a certain network (subnet is 10.10.11.x) I need to jump through an intermediate host to reach my destination because of destination port I can\'t change and limited
My solution to this problem is the following:
Host myserver
HostName [internal IP]
...
Match Host [internal IP] !Exec "nc -w1 -q0 %h %p < /dev/null"
ProxyCommand ssh jumphost -W %h:%p
It's important to have the Host myserver
lines first, so the SSH client will know the IP address.
In the Match
expression,
Host
option matches on that IP. (It accepts *
, so you can match to /8, /16 or /24 subnets too.)Exec
option executes a netcat
with a 1 second timeout to test if the SSH port is open. If not, the ProxyCommand
is used.This is the clearest way I found to actually test if you need a jumphost or not. If your network is lagging, you can set higher timeouts, of course. See man ssh_config for more details.