This is a fork of repository adding proxy handling.
Go to file
Darshil Chanpura bd8a1b8cd0 Added metrics endpoint 2022-07-30 15:53:05 +05:30
blocker Minor edits in block logic 2022-07-25 11:11:32 +05:30
docs Added docs and some minor improvements to code 2022-01-23 12:17:24 +05:30 Added docs and some minor improvements to code 2022-01-23 12:17:24 +05:30
go.mod Added metrics endpoint 2022-07-30 15:53:05 +05:30
go.sum Added metrics endpoint 2022-07-30 15:53:05 +05:30
gokrazy.tar.gz Added example gokrazy.tar.gz 2022-01-23 17:37:55 +05:30
main.go Added metrics endpoint 2022-07-30 15:53:05 +05:30

Tun-Tana-Tun (टन-टना-टन)

This project is a simple TCP Proxy allows bring remote ports listening on localhost.

This main reason why this project exists is to be used with gokrazy on Raspberry Pi.


Usage of tuntanatun:
        Enable Logs
  -local string
        Local Address (default "localhost:9999")
  -remote string
        Remote Address (default "localhost:80")

A simple use case

By using gokrazy there are challenges in creating a network interface and running Tailscale on it, so we use userspace networking mode of Tailscale.

There are work-arounds in accessing the peers using HTTP_PROXY variable, like most of the HTTP Requests can use this variable and proxy it through, the problem comes when there is a need to connect to a port with non-HTTP like connecting to a Database.

The simple solution is to use SOCKS proxy, which allows all traffic to be proxied, and fortunately tailscaled allows setting a SOCKS5 proxy listener/server through command line arguments.

Now we can try to connect to the desired service/server in VPN, but alas, there's one more problem.

To use this proxy the program should respect the proxy variable like ALL_PROXY, we know HTTP_PROXY is always used for any net/http functions but as this SOCKS proxy implementation is not yet in standard library normal packages don't use it.

One option is to change the service code to use this proxy implementation, which is simply a change in net.Dialer using proxy.FromEnvironment(). Which requires changes in possibly everything and building again.

Another option is to bring that port, from remote server to localhost. This is also called tunneling, or port forwarding. We use a local port and connect to remote host:port and proxy it.

Following diagram shows this in action.