From 1448da0af14b0ffd2037105d034ba89ed8c75f86 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Thu, 21 Apr 2022 18:57:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20rust=20=E4=B8=8E=20bore=20?= =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 7 +++++ rust/bore.md | 73 +++++++++++++++++++++++++++++++++++++++++++ rust/install-rust.md | 34 ++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 rust/bore.md create mode 100644 rust/install-rust.md diff --git a/.vscode/settings.json b/.vscode/settings.json index 1a40391..9e551c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,4 +22,11 @@ "pasteImage.path": "${currentFileDir}/images", "pasteImage.showFilePathConfirmInputBox": true, "prettier.singleQuote": false, + "spellright.language": [ + "zh-CN" + ], + "spellright.documentTypes": [ + "latex", + "plaintext" + ], } diff --git a/rust/bore.md b/rust/bore.md new file mode 100644 index 0000000..7b571f5 --- /dev/null +++ b/rust/bore.md @@ -0,0 +1,73 @@ +--- +tags: #rust #network #bore +--- + +# [bore](https://github.com/ekzhang/bore) +`Rust` 中的一个现代、简单的 `TCP` 隧道,它将本地端口暴露给远程服务器,绕过标准 `NAT` 。这就是它所做的一切:不多也不少。 + +## 安装 +> 需要有rust环境,rust环境安装参照 [[install-rust]] 。 +```bash +cargo install bore-cli +``` +*安装的时候会从 `github` 拉 `crates.io-index` ,要上 `github` 啊,可恶,根本上不去。* + + +## 服务端使用 +先在云服务器把防火墙打开想要开放的端口,以及开放 `bore` 的对外端口 `7835`。 + +客户端是通过连接 `7835` 来进行握手,然后才从其它端口建立连接。 + +然后直接运行 `bore server` 就可以开始监听了。 +``` +$ bore server +2022-04-21T07:08:49.256539Z INFO bore_cli::server: server listening addr=0.0.0.0:7835 +``` + + +## 客户端使用 +确认要映射的端口,服务端地址 +``` +$ bore local 22 --to hostname +``` +直接这样连的话,端口是随机分配的,要指定端口需要使用 `--port ` 命令行参数。 +``` +$ bore local 22 --to jie65535.top --port 9022 +2022-04-21T09:11:39.835236Z INFO bore_cli::client: connected to server remote_port=9022 +2022-04-21T09:11:39.835322Z INFO bore_cli::client: listening at jie65535.top:9022 +``` + +## 服务端帮助 +``` +bore-server 0.3.0 +Runs the remote proxy server + +USAGE: + bore server [OPTIONS] + +OPTIONS: + -h, --help Print help information + --min-port Minimum TCP port number to accept [default: 1024] + -s, --secret Optional secret for authentication [env: BORE_SECRET] + -V, --version Print version information +``` + +## 客户端帮助 +``` +bore-local 0.3.0 +Starts a local proxy to the remote server + +USAGE: + bore local [OPTIONS] --to + +ARGS: + The local port to expose + +OPTIONS: + -h, --help Print help information + -l, --local-host The local host to expose [default: localhost] + -p, --port Optional port on the remote server to select [default: 0] + -s, --secret Optional secret for authentication [env: BORE_SECRET] + -t, --to Address of the remote server to expose local ports to + -V, --version Print version information +``` \ No newline at end of file diff --git a/rust/install-rust.md b/rust/install-rust.md new file mode 100644 index 0000000..5d0fe50 --- /dev/null +++ b/rust/install-rust.md @@ -0,0 +1,34 @@ +--- +tags: #rust +--- +# 安装Rust环境 + +从`https://sh.rustup.rs`获取安装脚本,执行脚本安装 + +```bash +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +source $HOME/.cargo/env && rustup default nightly && rustup update +``` + +建议切换到`nightly`通道,更新使用。 + +--- + +## 更换国内源 +使用时发现它还得上github获取索引,如果访问github有困难,可以换源。 +在 `~/.cargo/` 目录下 `touch config`,添加如下内容: +``` +[source.crates-io] +registry = "https://github.com/rust-lang/crates.io-index" +replace-with = 'ustc' +[source.ustc] +registry = "https://mirrors.ustc.edu.cn/crates.io-index" +``` +就可以更改为国内源 + +要通过系统 `git` 访问 `github` 的话,还可以加上以下内容 +``` +[net] +git-fetch-with-cli = true +``` +如果有 `Cargo` 不支持的特殊身份验证要求,将其设置为 `true` 会很有帮助。否则会使用 `cargo` 自带的 `git`。 \ No newline at end of file