Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 803
miki Avatar asked Dec 18 '25 15:12

miki


1 Answers

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.

like image 83
jeb Avatar answered Dec 20 '25 10:12

jeb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!