如何使用 Granados 和 C# 通过 SSH 隧道转发端口
我正在使用 Granados SSH 库,并且尝试将本地主机上的端口 3306 转发到远程主机上的端口 3306(即 MySQL 服务器端口)。也就是说,我希望能够通过 SSH 隧道连接到远程主机的 MySQL 服务器。
这是我目前尝试使用 Granada .NET SSH 库但似乎不起作用的示例:
public SSHConnection _conn;
_conn.ListenForwardedPort("localhost", 3306); //doesn't work
有人可以告诉我如何实现我想要的吗?
I'm using the Granados SSH Library and I'm trying to forward port 3306 on my localhost to port 3306 on the remote host (i.e. the MySQL server port). That is, I want to be able to make connections to the remote host's MySQL server through the SSH tunnel.
Here is an example of what I've currently tried using the Granada .NET SSH library but which doesn't seem to work:
public SSHConnection _conn;
_conn.ListenForwardedPort("localhost", 3306); //doesn't work
Can somebody please tell me how I can achieve what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的术语倒退了!您想要做的是从本地计算机到远程系统的隧道。这是因为远程系统是 TCP服务器,因此连接是在本地系统上发起并在远程系统上接受的。
ListenForwardedPort
方法用于另一个方向。我没有对此进行测试,但从我对 Granados 源代码的阅读来看,我认为您需要使用
ForwardPort
方法。它需要四个与主机相关的参数,如下所示:remote_host
:带有服务器的主机,即您的 MySQL 服务器remote_port
:服务器正在侦听的端口,即 3306originator_host
:本地想要监听的主机,可能是“localhost”originator_port
:本地想要连接的主机的端口,可以重复使用 3306 或选择任何其他可用的数字您的 MySQL 服务器,
remote_host
,可能是“localhost”(如 SSH 连接的另一个端点所见),但它也可以是通过以下方式可访问的任何计算机远程系统。您还可以使用远程系统的 IP 地址,即 localhost 或 127.0.0.1 以外的地址。You have your terminology backwards! What you are trying to do is tunnel from the local machine to the remote system. This is because the remote system is the TCP server so a connection is initiated on your local system and accepted on the remote system. The
ListenForwardedPort
method is for the other direction.I didn't test this but from my read of the Granados source code I think you want the
ForwardPort
method instead. It takes four host-related arguments like this:remote_host
: the host with the server on it, i.e. your MySQL serverremote_port
: the port the server is listening on, i.e. 3306originator_host
: the host you want to listen on the local side, probably "localhost"originator_port
: the port of the host you want to connect to on the local side, you can re-use 3306 or pick any other available numberYour MySQL server, the
remote_host
, might be "localhost" (as seen by the other endpoint of the SSH connection) but it could also be any machine reachable by the remote system. You can also use the IP address of the remote system, i.e. something other than localhost or 127.0.0.1.