
軽量で高性能なNAT越え用リバースプロキシ。Rustで記述されています。frpやngrokの代替品です。

安全で安定した、高性能なNAT越えリバースプロキシ。Rustで記述。
ratholeは、frpやngrokと同様に、公開IPを持つサーバーを介して、NAT配下のデバイス上のサービスをインターネットに公開するのに役立ちます。
フル機能のratholeはリリースページから入手できます。またはソースからビルドして他のプラットフォームに対応したりバイナリを最小化することもできます。Dockerイメージも利用可能です。
ratholeの使い方はfrpと非常に似ています。frpの経験があれば、設定は非常に簡単です。唯一の違いは、サービスの設定がクライアント側とサーバー側に分割されており、トークンが必須であることです。
ratholeを使用するには、パブリックIPを持つサーバーと、NATの背後にあるデバイス(インターネットに公開する必要のあるサービスが動作しているデバイス)が必要です。
自宅のNAT配下にNASがあり、そのSSHサービスをインターネットに公開したいとします。
以下の内容でserver.tomlを作成し、必要に応じて調整してください。
# server.toml
[server]
bind_addr = "0.0.0.0:2333" # `2333` specifies the port that rathole listens for clients
[server.services.my_nas_ssh]
token = "use_a_secret_that_only_you_know" # Token that is used to authenticate the client for the service. Change to an arbitrary value.
bind_addr = "0.0.0.0:5202" # `5202` specifies the port that exposes `my_nas_ssh` to the Internet
Then run:
./rathole server.toml
以下の内容でclient.tomlを作成し、必要に応じて調整してください。
# client.toml
[client]
remote_addr = "myserver.com:2333" # The address of the server. The port must be the same with the port in `server.bind_addr`
[client.services.my_nas_ssh]
token = "use_a_secret_that_only_you_know" # Must be the same with the server to pass the validation
local_addr = "127.0.0.1:22" # The address of the service that needs to be forwarded
Then run:
./rathole client.toml
myserver.comのポート2333に接続を試み、myserver.com:5202へのすべてのトラフィックがクライアントのポート22に転送されます。したがって、ssh myserver.com:5202を使用してNASにSSH接続できます。
Linuxでratholeをバックグラウンドサービスとして実行するには、systemdの例を参照してください。
ratholeは、設定ファイルの内容に基づいてサーバーモードとクライアントモードを自動的に判別できます。クイックスタートの例のように、[server]と[client]のブロックの一方のみが存在する場合です。
ただし、[client]と[server]のブロックを1つのファイルにまとめることもできます。その場合は、サーバー側でrathole --server config.tomlを、クライアント側でrathole --client config.tomlを実行して、明示的に実行モードを指定します。
完全な設定仕様に進む前に、設定例に目を通して設定形式を把握することをお勧めします。
暗号化とtransportブロックの詳細については、Transportを参照してください。
以下が完全な設定仕様です:
[client]
remote_addr = "example.com:2333" # Necessary. The address of the server
default_token = "default_token_if_not_specify" # Optional. The default token of services, if they don't define their own ones
heartbeat_timeout = 40 # Optional. Set to 0 to disable the application-layer heartbeat test. The value must be greater than `server.heartbeat_interval`. Default: 40 seconds
retry_interval = 1 # Optional. The interval between retry to connect to the server. Default: 1 second
[client.transport] # The whole block is optional. Specify which transport to use
type = "tcp" # Optional. Possible values: ["tcp", "tls", "noise"]. Default: "tcp"
[client.transport.tcp] # Optional. Also affects `noise` and `tls`
proxy = "socks5://user:[email protected]:1080" # Optional. The proxy used to connect to the server. `http` and `socks5` is supported.
nodelay = true # Optional. Determine whether to enable TCP_NODELAY, if applicable, to improve the latency but decrease the bandwidth. Default: true
keepalive_secs = 20 # Optional. Specify `tcp_keepalive_time` in `tcp(7)`, if applicable. Default: 20 seconds
keepalive_interval = 8 # Optional. Specify `tcp_keepalive_intvl` in `tcp(7)`, if applicable. Default: 8 seconds
[client.transport.tls] # Necessary if `type` is "tls"
trusted_root = "ca.pem" # Necessary. The certificate of CA that signed the server's certificate
hostname = "example.com" # Optional. The hostname that the client uses to validate the certificate. If not set, fallback to `client.remote_addr`
[client.transport.noise] # Noise protocol. See `docs/transport.md` for further explanation
pattern = "Noise_NK_25519_ChaChaPoly_BLAKE2s" # Optional. Default value as shown
local_private_key = "key_encoded_in_base64" # Optional
remote_public_key = "key_encoded_in_base64" # Optional
[client.transport.websocket] # Necessary if `type` is "websocket"
tls = true # If `true` then it will use settings in `client.transport.tls`
[client.services.service1] # A service that needs forwarding. The name `service1` can change arbitrarily, as long as identical to the name in the server's configuration
type = "tcp" # Optional. The protocol that needs forwarding. Possible values: ["tcp", "udp"]. Default: "tcp"
token = "whatever" # Necessary if `client.default_token` not set
local_addr = "127.0.0.1:1081" # Necessary. The address of the service that needs to be forwarded
nodelay = true # Optional. Override the `client.transport.nodelay` per service
retry_interval = 1 # Optional. The interval between retry to connect to the server. Default: inherits the global config
[client.services.service2] # Multiple services can be defined
local_addr = "127.0.0.1:1082"
[server]
bind_addr = "0.0.0.0:2333" # Necessary. The address that the server listens for clients. Generally only the port needs to be change.
default_token = "default_token_if_not_specify" # Optional
heartbeat_interval = 30 # Optional. The interval between two application-layer heartbeat. Set to 0 to disable sending heartbeat. Default: 30 seconds
[server.transport] # Same as `[client.transport]`
type = "tcp"
[server.transport.tcp] # Same as the client
nodelay = true
keepalive_secs = 20
keepalive_interval = 8
[server.transport.tls] # Necessary if `type` is "tls"
pkcs12 = "identify.pfx" # Necessary. pkcs12 file of server's certificate and private key
pkcs12_password = "password" # Necessary. Password of the pkcs12 file
[server.transport.noise] # Same as `[client.transport.noise]`
pattern = "Noise_NK_25519_ChaChaPoly_BLAKE2s"
local_private_key = "key_encoded_in_base64"
remote_public_key = "key_encoded_in_base64"
[server.transport.websocket] # Necessary if `type` is "websocket"
tls = true # If `true` then it will use settings in `server.transport.tls`
[server.services.service1] # The service name must be identical to the client side
type = "tcp" # Optional. Same as the client `[client.services.X.type]
token = "whatever" # Necessary if `server.default_token` not set
bind_addr = "0.0.0.0:8081" # Necessary. The address of the service is exposed at. Generally only the port needs to be change.
nodelay = true # Optional. Same as the client
[server.services.service2]
bind_addr = "0.0.0.1:8082"
ratholeは、多くのRustプログラムと同様に、環境変数を使用してログレベルを制御します。info、warn、error、debug、traceが利用可能です。
RUST_LOG=error ./rathole config.toml
を実行すると、エラーレベルのログのみが出力されます。
RUST_LOGが設定されていない場合、デフォルトのログレベルはinfoです。
v0.4.7以降、ratholeはデフォルトでTCP_NODELAYを有効にしており、これによりRDPやMinecraftサーバーなどのインタラクティブなアプリケーションのレイテンシが改善されます。ただし、帯域幅がわずかに低下します。
帯域幅がより重要な場合は、nodelay = falseでTCP_NODELAYを無効にできます。
ratholeはfrpと同程度のレイテンシですが、より多くの接続を処理でき、より広い帯域幅を提供し、メモリ使用量が少なくなります。
詳細については、別ページのベンチマークを参照してください。
ただし、ここからratholeがあなたの転送サービスを以前より数倍速く魔法のように改善できると受け取らないでください。 ベンチマークはローカルループバック上で行われており、タスクがCPUバウンドである場合のパフォーマンスを示しています。ネットワークがボトルネックでない場合、かなりの改善が見込まれます。残念ながら、多くのユーザーには当てはまりません。その場合、主な利点はリソース消費の低減であり、帯域幅やレイテンシは大幅に改善されない可能性があります。

対象外には、実装予定のない機能とその理由が記載されています。