SSH connections using ProxyCommand

Scenario, you have a bunch of servers on your LAN with no access to the internet and you want to be able to connect to them via a specific server.

In this case, all your servers you wan’t to connect to resolves to *.example.tld. Hence, *.example.tld in the Host line. You can of course have a single host here. Tips, if you do set Host to *.example.tld and then proxy via for example in.example.tld, it will not work (I don’t have an explanation). I opted simply to use another domain for the “incomming connection” server.

Anyway, add lines similar to these to your ~/.ssh/config

Host *.example.tld
ProxyCommand ssh proxy.someother.tld 'nc -w 120 %h %p'

and you’re set!

Now when you ssh to server1.example.tld ssh will actually connect using the command ssh proxy.someother.tld 'nc -w 120 server1.example.tld'.

Pretty neat and very, very useful!