bore README

The project's README from github.com/ekzhang/bore. As one markdown file: README.md.

bore

Build status Crates.io

A modern, simple TCP tunnel in Rust that exposes local ports to a remote server, bypassing standard NAT connection firewalls. That's all it does: no more, and no less.

Video demo

# Installation (requires Rust, see alternatives below)
cargo install bore-cli

# On your local machine
bore local 8000 --to bore.pub

This will expose your local port at localhost:8000 to the public internet at bore.pub:<PORT>, where the port number is assigned randomly.

Similar to localtunnel and ngrok, except bore is intended to be a highly efficient, unopinionated tool for forwarding TCP traffic that is simple to install and easy to self-host, with no frills attached.

(bore totals about 400 lines of safe, async Rust code and is trivial to set up — just run a single binary for the client and server.)

Installation

macOS

bore is packaged as a Homebrew core formula.

brew install bore-cli

Linux

Arch Linux

bore is available in the AUR as bore.

yay -S bore # or your favorite AUR helper

Gentoo Linux

bore is available in the gentoo-zh overlay.

sudo eselect repository enable gentoo-zh
sudo emerge --sync gentoo-zh
sudo emerge net-proxy/bore

Binary Distribution

Otherwise, the easiest way to install bore is from prebuilt binaries. These are available on the releases page for macOS, Windows, and Linux. Just unzip the appropriate file for your platform and move the bore executable into a folder on your PATH.

Cargo

You also can build bore from source using Cargo, the Rust package manager. This command installs the bore binary at a user-accessible path.

cargo install bore-cli

Docker

We also publish versioned Docker images for each release. The image is built for an AMD 64-bit architecture. They're tagged with the specific version and allow you to run the statically-linked bore binary from a minimal "scratch" container.

docker run -it --init --rm --network host ekzhang/bore <ARGS>

Detailed Usage

This section describes detailed usage for the bore CLI command.

Local Forwarding

You can forward a port on your local machine by using the bore local command. This takes a positional argument, the local port to forward, as well as a mandatory --to option, which specifies the address of the remote server.

bore local 5000 --to bore.pub

You can optionally pass in a --port option to pick a specific port on the remote to expose, although the command will fail if this port is not available. Also, passing --local-host allows you to expose a different host on your local area network besides the loopback address localhost.

The full options are shown below.

Starts a local proxy to the remote server

Usage: bore local [OPTIONS] --to <TO> <LOCAL_PORT>

Arguments:
  <LOCAL_PORT>  The local port to expose [env: BORE_LOCAL_PORT=]

Options:
  -l, --local-host <HOST>  The local host to expose [default: localhost]
  -t, --to <TO>            Address of the remote server to expose local ports to [env: BORE_SERVER=]
  -p, --port <PORT>        Optional port on the remote server to select [default: 0]
  -s, --secret <SECRET>    Optional secret for authentication [env: BORE_SECRET]
  -h, --help               Print help

Self-Hosting

As mentioned in the startup instructions, there is a public instance of the bore server running at bore.pub. However, if you want to self-host bore on your own network, you can do so with the following command:

bore server

That's all it takes! After the server starts running at a given address, you can then update the bore local command with option --to <ADDRESS> to forward a local port to this remote server.

It's possible to specify different IP addresses for the control server and for the tunnels. This setup is useful for cases where you might want the control server to be on a private network while allowing tunnel connections over a public interface, or vice versa.

The full options for the bore server command are shown below.

Runs the remote proxy server

Usage: bore server [OPTIONS]

Options:
      --min-port <MIN_PORT>          Minimum accepted TCP port number [env: BORE_MIN_PORT=] [default: 1024]
      --max-port <MAX_PORT>          Maximum accepted TCP port number [env: BORE_MAX_PORT=] [default: 65535]
  -s, --secret <SECRET>              Optional secret for authentication [env: BORE_SECRET]
      --bind-addr <BIND_ADDR>        IP address to bind to, clients must reach this [default: 0.0.0.0]
      --bind-tunnels <BIND_TUNNELS>  IP address where tunnels will listen on, defaults to --bind-addr
  -h, --help                         Print help

Protocol

There is an implicit control port at 7835, used for creating new connections on demand. At initialization, the client sends a "Hello" message to the server on the TCP control port, asking to proxy a selected remote port. The server then responds with an acknowledgement and begins listening for external TCP connections.

Whenever the server obtains a connection on the remote port, it generates a secure UUID for that connection and sends it back to the client. The client then opens a separate TCP stream to the server and sends an "Accept" message containing the UUID on that stream. The server then proxies the two connections between each other.

For correctness reasons and to avoid memory leaks, incoming connections are only stored by the server for up to 10 seconds before being discarded if the client does not accept them.

Authentication

On a custom deployment of bore server, you can optionally require a secret to prevent the server from being used by others. The protocol requires clients to verify possession of the secret on each TCP connection by answering random challenges in the form of HMAC codes. (This secret is only used for the initial handshake, and no further traffic is encrypted by default.)

# on the server
bore server --secret my_secret_string

# on the client
bore local <LOCAL_PORT> --to <TO> --secret my_secret_string

If a secret is not present in the arguments, bore will also attempt to read from the BORE_SECRET environment variable.

Acknowledgements

Created by Eric Zhang (@ekzhang1). Licensed under the MIT license.

The author would like to thank the contributors and maintainers of the Tokio project for making it possible to write ergonomic and efficient network services in Rust.

bore (ekzhang/bore)

Searching Database…

11.5K ·GitHub
这是什么?bore 是一个用 Rust 编写的简单命令行工具,可以创建 TCP 隧道,把本地端口暴露给远程服务器,绕过 NAT 和防火墙,类似于 ngrok 或 localtunnel。
这是库还是独立的命令行工具?它是一个独立的命令行程序,有两个子命令:'bore local' 用于客户端,'bore server' 用于自建隧道服务器。它不是库。
我该怎么把它运行起来?在 macOS 上可以通过 Homebrew 安装,在 Arch Linux 上可以通过 AUR 安装,也可以下载发布页面上的预编译二进制文件、使用 cargo install,或使用 Docker。然后运行 'bore local --to bore.pub',即可把本地端口转发到公共服务器 bore.pub。
我需要先安装 Rust 或 Cargo 吗?不需要。只有在选择用 'cargo install' 从源码构建时才需要 Rust/Cargo;预编译二进制、Homebrew、AUR 包和 Docker 镜像都可以作为替代方案。
bore 会加密我的隧道流量吗?不会,默认情况下,初始握手之后的任何流量都不会再加密。可以通过 BORESECRET 变量设置密钥用于身份验证,但它只保护握手过程,不保护数据本身。
bore.pub 是给谁用的?我能不依赖它吗?bore.pub 是一个免费的公共实例,适合快速测试;但如果想要私有或更可控的部署,任何人都可以用 'bore server' 自建自己的服务器。
bore 支持哪些平台?提供 macOS、Windows 和 Linux 的预编译二进制文件;macOS 可以使用 Homebrew,Linux 可以使用 AUR 和 Gentoo overlay 软件包。
通过公共服务器 bore.pub 的流量是私密的吗?默认情况下,握手之后的流量不加密,以明文方式经过代理转发。因此,除非你自己添加加密层,否则任何运行或拦截服务器的人都可能看到数据。
bore 的代码库有多大?它刻意保持得很小,大约 400 行安全的异步 Rust 代码。作者强调,这让它更简单,也更容易自建。
隧道协议实际是如何工作的?客户端向服务器的控制端口(7835)发送 Hello 消息,请求一个远程端口。当有新的外部连接到达时,服务器会生成一个 UUID,客户端随即打开一个新的数据流,并发送带有该 UUID 的 Accept 消息,服务器再把这两个连接代理连接在一起。
我能在 Docker 中运行 bore 吗?可以。每个版本都会发布带版本号的 Docker 镜像,针对 AMD64 构建,并在一个精简的 scratch 容器中运行静态链接的二进制文件。
我能选择暴露哪个远程端口吗?可以,你可以传入 --port 选项来请求远程服务器上的特定端口;但如果该端口不可用,命令会失败。默认会随机分配一个端口。
What are similar projects?cloudflared, ProxyBridge, chisel, dufs, gost, gping, oha, rathole
Creator
ekzhang
Size
0.1 MB
Stars
11.5K
Age
4y
Commits · 90 Days