帮助配置 SSH 隧道来访问远程服务器

帮助配置 SSH 隧道来访问远程服务器

这是我的场景:

192.168.2.222 --- VPN ---> 192.168.2.200 / 192.168.0.10 --- LAN ---> 192.168.0.50
My local machine           My remote machine                         Target server

由于我本地计算机的 VPN 接口 ( /24) 的网络掩码,我无法直接到达目标服务器。

但是,如果我通过 SSH 连接到远程计算机,那么我就可以访问它,因为远程(本地)接口位于目标服务器的同一子网上。

为了在本地计算机上使用一些工具,我想在远程计算机上启用 SSH 隧道。

例如,假设我要访问目标服务器上的 SQLServer 服务器(端口 3306)。我设置DBeaver在远程计算机上使用 SSH 隧道,但它无法连接到数据库。

在我的远程计算机上,sshd.config文件如下:

Include /etc/ssh/sshd_config.d/*.conf
ChallengeResponseAuthentication no
UsePAM yes
GatewayPorts yes
X11Forwarding yes
PrintMotd no
PermitTunnel yes
AcceptEnv LANG LC_*
Subsystem sftp  /usr/lib/openssh/sftp-server

为了手动测试它,我做了:

$local ssh -L 13306:192.168.0.50:3306 [email protected]
$local sqsh -S 192.168.0.50:13306 -U user -D database -P password

我有:

sqsh-2.5.16.1 Copyright (C) 1995-2001 Scott C. Gray
Portions Copyright (C) 2004-2014 Michael Peppler and Martin Wesdorp
This is free software with ABSOLUTELY NO WARRANTY
For more information type '\warranty'
Open Client Message
Layer 0, Origin 0, Severity 78, Number 41
Unable to connect: Adaptive Server is unavailable or does not exist
Open Client Message
Layer 0, Origin 0, Severity 78, Number 41
Unable to connect: Adaptive Server is unavailable or does not exist

在我的远程计算机上发出完全相同的命令(当然使用 3306 而不是 13306)会导致连接成功。

我还从本地计算机检查了端口 13306,但它仍然关闭:

$local nmap 192.168.2.200 -p 13306

Starting Nmap 7.80 ( https://nmap.org ) at 2022-04-15 13:10 CEST
Nmap scan report for 192.168.2.200
Host is up (0.014s latency).

PORT      STATE  SERVICE
13306/tcp closed unknown

我应该进一步设置什么?

相关内容