SSH tunnel via multiple hops

i have 1 client (Windows OS) and 4 VPS (Linux OS) .

i want create Socks v5 proxy with ssh tunnel for connect client to VPS-4 .

client -> VPS-1 -> VPS-2 -> VPS-3 -> VPS-4 -> internet

in client with CMD i connect to VPS-1 with command :

ssh -L9999:localhost:9999 root@VPS-1-IPaddress 

inside VPS-1 ssh window : for connect VPS-1 to VPS-2 i use command

ssh -Dlocalhost:9999 root@VPS-2-IPaddress 

and inside VPS-2 ssh window : for connect VPS-2 to VPS-3 i use command

ssh -Dlocalhost:9999 root@VPS-3-IPaddress 

and inside VPS-3 ssh window : for connect VPS-3 to VPS-4 i use command

ssh -Dlocalhost:9999 root@VPS-4-IPaddress 

when i set "localhost" and port "9999" in browser proxy setting and open website whatismyipaddress i see VPS-2 IP address .

i must see VPS-4 IP address . i don't know what is problem .

anyone can advise me ?

1 Answer

Too much manual work.

When using a ~/.ssh/config file

HOST VPS-4-IPaddress user root ProxyJump VPS-3-IPaddress HOST VPS-3-IPaddress user root ProxyJump VPS-2-IPaddress HOST VPS-2-IPaddress user root ProxyJump VPS-1-IPaddress HOST VPS-1-IPaddress user root ProxyJump VPS-2-IPaddress 

It's also possible to chain the proxies in one line

HOST VPS-4-IPaddress user root ProxyJump VPS-1-IPaddress,VPS-2-IPaddress,VPS-3-IPaddress 

Then you can use

ssh -D9999 root@VPS-4-IPaddress 

Or without a .ssh/config file, directly on the command line (-J is equal to -o ProxyJump=)

ssh -D9999 VPS-4-IPaddress -J VPS-1-IPaddress,VPS-2-IPaddress,VPS-3-IPaddress 

The manual way

You need to build local forwards from one machine to the next one.
The socks proxy will only be defined on the last one.

Client:> ssh -L9999:localhost:9999 root@VPS-1-IPaddress

VPS-1:> ssh -L9999:localhost:9999 root@VPS-2-IPaddress

VPS-2:> ssh -L9999:localhost:9999 root@VPS-3-IPaddress

VPS-3:> ssh -D9999 root@VPS-4-IPaddress

But the tunnel is more or less the same like the automatic variant.

7

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like