通过多跳的 SSH 隧道
SSH tunnel via multiple hops
我有 1 个客户 (Windows OS) 和 4 个 VPS (Linux OS) .
我想创建带有 ssh 隧道的 Socks v5 代理,以便将客户端连接到 VPS-4。
客户端 -> VPS-1 -> VPS-2 -> VPS-3 -> VPS-4 -> 互联网
在带有 CMD 的客户端中,我使用命令连接到 VPS-1 :
ssh -L9999:localhost:9999 root@VPS-1-IPaddress
inside VPS-1 ssh window : 为了连接 VPS-1 到 VPS-2 我使用命令
ssh -Dlocalhost:9999 root@VPS-2-IPaddress
和内部 VPS-2 ssh window :为了将 VPS-2 连接到 VPS-3 我使用命令
ssh -Dlocalhost:9999 root@VPS-3-IPaddress
和内部 VPS-3 ssh window :为了将 VPS-3 连接到 VPS-4 我使用命令
ssh -Dlocalhost:9999 root@VPS-4-IPaddress
当我在浏览器代理设置中设置“localhost”和端口“9999”并打开网站 whatismyipaddress 时
我看到 VPS-2 IP 地址。
我必须看到 VPS-4 IP 地址。我不知道有什么问题。
谁能给我建议?
手动工作太多。
使用 ~/.ssh/config 文件时
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
也可以将代理链接在一行中
HOST VPS-4-IPaddress
user root
ProxyJump VPS-1-IPaddress,VPS-2-IPaddress,VPS-3-IPaddress
那你就可以使用
ssh -D9999 root@VPS-4-IPaddress
或者没有.ssh/config文件,直接在命令行上(-J
等于-o ProxyJump=
)
ssh -D9999 VPS-4-IPaddress -J VPS-1-IPaddress,VPS-2-IPaddress,VPS-3-IPaddress
手动方式
您需要构建从一台机器到下一台机器的本地转发。
socks代理只会在最后一个定义。
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
但隧道与自动变体大致相同。
我有 1 个客户 (Windows OS) 和 4 个 VPS (Linux OS) .
我想创建带有 ssh 隧道的 Socks v5 代理,以便将客户端连接到 VPS-4。
客户端 -> VPS-1 -> VPS-2 -> VPS-3 -> VPS-4 -> 互联网
在带有 CMD 的客户端中,我使用命令连接到 VPS-1 :
ssh -L9999:localhost:9999 root@VPS-1-IPaddress
inside VPS-1 ssh window : 为了连接 VPS-1 到 VPS-2 我使用命令
ssh -Dlocalhost:9999 root@VPS-2-IPaddress
和内部 VPS-2 ssh window :为了将 VPS-2 连接到 VPS-3 我使用命令
ssh -Dlocalhost:9999 root@VPS-3-IPaddress
和内部 VPS-3 ssh window :为了将 VPS-3 连接到 VPS-4 我使用命令
ssh -Dlocalhost:9999 root@VPS-4-IPaddress
当我在浏览器代理设置中设置“localhost”和端口“9999”并打开网站 whatismyipaddress 时 我看到 VPS-2 IP 地址。
我必须看到 VPS-4 IP 地址。我不知道有什么问题。
谁能给我建议?
手动工作太多。
使用 ~/.ssh/config 文件时
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
也可以将代理链接在一行中
HOST VPS-4-IPaddress
user root
ProxyJump VPS-1-IPaddress,VPS-2-IPaddress,VPS-3-IPaddress
那你就可以使用
ssh -D9999 root@VPS-4-IPaddress
或者没有.ssh/config文件,直接在命令行上(-J
等于-o ProxyJump=
)
ssh -D9999 VPS-4-IPaddress -J VPS-1-IPaddress,VPS-2-IPaddress,VPS-3-IPaddress
手动方式
您需要构建从一台机器到下一台机器的本地转发。
socks代理只会在最后一个定义。
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
但隧道与自动变体大致相同。