Windows – uTorrent and PuTTY -> How to turn the connection into an active one

port-forwardingputtyssh-tunneltunnelwindows 7

There is an active, and passive mode when we talk about torrent. Passive, is when you can't connect to the peers actively. Active is when your ports are forwarder, and others can connect to you.

What I did so far, is installed a Debian on my server. Then I added GatewayPorts yes into my sshd_config file. After that, in PuTTY, I set up the following configuration:
– Remote ports do the same
– Local ports accept connections from other hosts
Then I added a new forward like:
4D8080 (IPv4, Dynamic, at my PC's port 8080).

After this, I set my uTorrent to use SOCKS5 proxy for every possible connection, at localhost, port 8080. But, my client will show the red sign at the bottom-right part.

Is there a solution to this? (Something is surely not right, I get 0 DHT nodes too.)

Best Answer

Your two problems (not being connectable and not finding DHT nodes) are related, but they have different causes and different (partial) solutions.

Connectivity

To be able to accept incoming connections, you have to accomplish three things:

  • Forward the remote port uTorrent listens to to your client machine.

    In Preferences → Connection → Listening Port → Port used for incoming connections, uTorrent lets you specify a single port for incoming connections. Set it to 40000 (for example).

    To forward this port, enter Connection → SSH → Tunnels in PuTTY and add the following forwarded port:

    R40000 127.0.0.1:40000
    

    Checking Local ports accept connections from other hosts is neither required nor desired for this. It's used to allow other machines to connect to your computer and make use of the forwarded local and dynamic ports.

    Checking Remote ports do the same is only required if you set GatewayPorts to clientspecified on your server. If it is set to yes or no, this option has no effect.

  • Make uTorrent report the correct IP to the tracker.

    By default, the tracker results to its best guess when adding an IP to the peer list. The dynamic port forwarding might (this depends on the tracker) cause a local IP address (10.xxx.yyy.zzz) to get added to the peer list. The IP that should get added instead is the one of your server.

    You can specify it in Preferences → BitTorrent → IP/Hostname to report to tracker. Not all trackers respect this setting, but it should help.

  • Allow uTorrent to accept incoming connections.

    In Preferences → Advanced, you can modify the bit field bt.transp_disposition.

    When using a SSH tunnel with remote port forwarding for TCP and UDP connections (see below), I'd set it to 13. This allows outgoing TCP and incoming TCP and UDP peer-to-peer connections.

DHT / UDP connections

PuTTY and SSH don't listen on any UDP port, so neither the dynamic nor the remote port you forwarded will work out of the box. Since DHT uses UDP, it won't work either.

  • Incoming UDP connections

    If you install socat on you server (apt-get install socat) and on your client machine (using Socat for Windows), you can transform incoming UDP connections to TCP connections, forward them through the tunnel and convert them back to UDP connections on your client machine.

    To do so, execute

    socat udp4-listen:40000,reuseaddr,fork tcp:localhost:50000
    

    on your server and

    socat tcp4-listen:50000,reuseaddr,fork UDP:localhost:40000
    

    on your client machine.

    The choice of port number 50000 is arbitrary, but it has to be different from 40000 (to be able to distinguish one connection type from the other).

    For the actual forwarding, enter Connection → SSH → Tunnels in PuTTY and add the following forwarded port:

    R50000 127.0.0.1:50000
    
  • Outgoing UDP connections

    Routing outgoing UDP connections through the SSH tunnel isn't as easy and might even be impossible. The method from above won't work since socat only listens to a specific port, while the destination port of an outgoing connection could be anything. Also, once a TCP packet reaches the dynamically forwarded port, you can't control what happens to it.

    It would be possible to set up UDP connections on a peer-by-peer basis, but that's probably not worth the effort. DHT should work fine with incoming connections, once you've conected to the first peer.

Related Question