要说 什么简单 省心

唯有 穿透

就是有点耗 流量红尘

定义

这是个内网穿透工具 类似于 frp nps

安装

alpine

1
2
3
4
wget https://mirror.nju.edu.cn/alpine/edge/testing/x86_64/rathole-0.5.0-r0.apk
apk add ./rathole-0.5.0-r0.apk

mkdir /etc/rathole

/etc/init.d/ratholec

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/sbin/openrc-run

name="Rathole Client Service"
description="Rathole Client Service"
command="/usr/bin/rathole"
command_args="-c /etc/rathole/rathole.toml"
pidfile="/run/$SVCNAME.pid"
command_background=true

depend() {
need net
after firewall
}
1
2
3
chmod +x /etc/init.d/ratholec
rc-service ratholec start
rc-update add ratholec

debian

1
2
3
4
5
6
apt install unzip
wget https://github.com/yujqiao/rathole/releases/download/v0.5.0/rathole-x86_64-unknown-linux-gnu.zip
unzip -d /usr/bin/ rathole-x86_64-unknown-linux-gnu.zip
chmod +x /usr/bin/rathole

mkdir /etc/rathole

/etc/systemd/system/ratholes.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=Rathole Server Service
After=network.target

[Service]
Type=simple
Restart=on-failure
RestartSec=5s
LimitNOFILE=1048576
User=root

WorkingDirectory=/etc/rathole
ExecStart=/usr/bin/rathole -s /etc/rathole/rathole.toml

[Install]
WantedBy=multi-user.target
1
systemctl enable ratholes.service --now

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[server]
# 服务器监听了这个端口
bind_addr = "0.0.0.0:2333"
default_token = "rathole"

[client]
# 客户端通过ip与端口进行连接
remote_addr = "{ip}:2333"
default_token = "rathole"

# 加密方式如下
[server.transport]
type = "noise"
[server.transport.noise]
local_private_key = "nKdq0NUp3pcnRzfQEtFI/Qe/GdO6zYh1G56etEZgeIo="

[client.transport]
type = "noise"
[client.transport.noise]
remote_public_key = "OZgtXqojrnphLrNL/o8tFYxkRDCPNaoRfRxbuMOgqHg="

# 服务端起了一个叫 go 的服务 对外端口为 16070
[server.services.go]
bind_addr = "0.0.0.0:16070"

# 客户端将本机的 6070 端口 转发给服务端的 go 服务
[client.services.go]
local_addr = "127.0.0.1:6070"

这个配置文件可以写到一起 他是用 命令 去区分 当前是运行的 服务端 --server 还是 客户端 --client
置于区分是不是同一个服务 用的是 services.{name} 进行区分的
这个keyrathole --genkey 生成

运行

supervisor

1
2
3
4
[program:rathole]
command=rathole --client /data/rathole/config.toml
directory=/data/rathole
user=root