rtun は、パブリック ゲートウェイ サーバーを介して TCP および UDP ポートをインターネットに公開するツールです。ファイアウォールと NAT の背後にあるマシン上で ssh および mosh サーバーを公開できます。
コンパイルされたバイナリはリリース ページから入手できます。独自のものを構築するには、リポジトリのクローンを作成して以下を作成します。
$ git clone https://github.com/snsinfu/reverse-tunnel
$ cd reverse-tunnel
$ makeまたは、
$ go build -o rtun github.com/snsinfu/reverse-tunnel/agent/cmd
$ go build -o rtun-server github.com/snsinfu/reverse-tunnel/server/cmd Docker イメージが利用可能です。
簡単な使用方法:
$ docker run -it
-p 8080:8080 -p 9000:9000
-e RTUN_AGENT="8080/tcp @ samplebfeeb1356a458eabef49e7e7"
snsinfu/rtun-server
$ docker run -it --network host
-e RTUN_GATEWAY="ws://0.1.2.3:9000"
-e RTUN_KEY="samplebfeeb1356a458eabef49e7e7"
-e RTUN_FORWARD="8080/tcp:localhost:8080"
snsinfu/rtunDocker イメージの Readme を参照してください。
rtun-server.ymlという名前の構成ファイルを作成します。
# Gateway server binds to this address to communicate with agents.
control_address : 0.0.0.0:9000
# List of authorized agents follows.
agents :
- auth_key : a79a4c3ae4ecd33b7c078631d3424137ff332d7897ecd6e9ddee28df138a0064
ports : [10022/tcp, 60000/udp] openssl rand -hex 32を使用してauth_key生成するとよいでしょう。エージェントはキーによって識別され、エージェントは構成ファイルにリストされているホワイトリストに登録されたポートのみを使用できます。
次に、ゲートウェイ サーバーを起動します。
$ ./rtun-serverこれで、エージェントはゲートウェイ サーバーに接続し、リバース トンネリングを開始できるようになります。サーバーとエージェントは通信に WebSocket を使用するため、ゲートウェイ サーバーはキャディなどの HTTPS リバース プロキシの背後に配置される場合があります。このようにして、トンネルを TLS によって保護できます。
rtun-server TLS 証明書の自動取得と更新をサポートしています。コントロール アドレスを:443に設定し、 domainパブリック ゲートウェイ サーバーのドメイン名に設定します。
control_address: :443
lets_encrypt:
domain: rtun.example.com
デフォルトでは、root 以外のユーザーはポート 443 を使用できません。おそらく、Linux 上でsetcap使用して、 rtun-server特権ポートにバインドできるようにしたい場合があります。
sudo setcap cap_net_bind_service=+ep rtun-server
rtun.ymlという名前の構成ファイルを作成します。
# Specify the gateway server.
gateway_url : ws://the-gateway-server.example.com:9000
# A key registered in the gateway server configuration file.
auth_key : a79a4c3ae4ecd33b7c078631d3424137ff332d7897ecd6e9ddee28df138a0064
forwards :
# Forward 10022/tcp on the gateway server to localhost:22 (tcp)
- port : 10022/tcp
destination : 127.0.0.1:22
# Forward 60000/udp on the gateway server to localhost:60000 (udp)
- port : 60000/udp
destination : 127.0.0.1:60000そしてエージェントを実行します:
$ ./rtun注: サーバーで TLS を使用している場合、ゲートウェイ URL はwss://ではなくws://で始まる必要があります。この場合、ポート番号はデフォルトである可能性が高くなります。
gateway_url : wss://the-gateway-server.example.com MITライセンス。