Double SOCKS5 proxy using SSH

Solution 1:

I assume that you are using openssh. The easiest way to do it is to use ProxyJump which appeared recently. You can use it from command line, effectively having the following command:

ssh -J ptitpou@jumpbox -D 9999 -tt ptitpou@targetserver

or from config file:

Host targetserver
    ProxyJump ptitpou@jumpbox
    DynamicForward 9999

Alternatively you can use ProxyCommand:

Host targetserver
    ProxyCommand ssh -W %h:%p ptitpou@jumpbox
    DynamicForward 9999