Creating a forwarded port within an SSH tunnel

前端 未结 2 1094
感情败类
感情败类 2020-12-06 05:38

I\'m attempting to use SSH.NET to create a tunnel from localhost:3306 to port 3306 on a remote machine:

  PrivateKeyFile file = new PrivateKeyFi         


        
2条回答
  •  北海茫月
    2020-12-06 06:27

    By changing the parameters of ForwardedPortLocal to:

        var port = new ForwardedPortLocal("localhost", 3306, "localhost", 3306);
    

    (to make it explicit which interface I was binding to), and adding the following code in just before port.Start();:

        port.RequestReceived += delegate(object sender, PortForwardEventArgs e)
        {
            Console.WriteLine(e.OriginatorHost + ":" + e.OriginatorPort);
        };
    

    I noticed the following being output:

        ::1:60309
    

    The e.OriginatorHost part of this was ::1, which is the IPv6 equivalent of localhost; however, the destination server was using IPv4. Changing the parameters to:

        var port = new ForwardedPortLocal("127.0.0.1", 3306, "localhost", 3306);
    

    forced the tunnel to run over IPv4 instead, and my code then worked exactly as I'd expected it to.

提交回复
热议问题